SlideShare a Scribd company logo
GROUP 1 PRESENTS
D …L P
USE Use a Do…Loop to execute a block of statements an indefinite number
of times. There are several variations of the Do...Loop statement, but
each evaluates a numeric condition to determine whether to continue
execution. As with If...Then, the condition must be a value or expression
that evaluates to False (zero) or to True (nonzero).
Do…Loop
}
In the following Do...Loop, the statements execute as
long as the condition is True:
Do While condition
statements
Loop
When Visual Basic executes this Do…Loop, it first tests condition. If condition is False (zero), it skips
past all the statements. If it's True (nonzero), Visual Basic executes the statements and then goes
back to the Do…While statement and tests the condition again.
Example :
Dim sum As Integer = 0
Dim counter As Integer = 0
Do While sum < 100
sum = sum + CInt(Textbox1.Text)
counter = counter + 1
Loop
MsgBox("The loop has run " & CStr(counter) & " times!")
Another variation of the Do...Loop statement executes the statements first
and then tests condition after each execution. This variation guarantees at
least one execution of statements:
Do
statements
Loop While condition
Example :
Dim sum As Integer = 0
Dim counter As Integer = 0
Do sum = sum + CInt(Textbox1.Text)
counter = counter + 1
Loop While sum < 100
MsgBox("The loop has run " & CStr(counter) & " times!")
Term Definition
Do Starts the definition of the Do loop.
While Repeat the loop until condition is False.
Until Repeat the loop until condition is True.
condition Boolean expression. If condition is Nothing, Visual Basic treats it as False.
statements One or more statements that are repeated while, or until, condition is True.
Continue Do Transfers control to the next iteration of the Do loop.
Exit Do Transfers control out of the Do loop.
Loop Terminates the definition of the Do loop.
You can use either While or Until to specify condition, but not both.
* The above example will keep on adding until counter > 1000.
The above example can be rewritten as :
Do
while counter <= 1000
num.Text = counter
counter = counter + 1
Loop
Example :
Do
num.Text = counter
counter = counter + 1
Loop Until counter > 1000
THANK
YOU

More Related Content

PPTX
Do...until loop structure
Jd Mercado
 
PDF
Java Repetiotion Statements
Huda Alameen
 
PPTX
Loop
kuldeep94
 
PDF
nuts and bolts of c++
guestfb6ada
 
PDF
Java input Scanner
Huda Alameen
 
PPTX
Looping statement in vb.net
ilakkiya
 
PPTX
What is while loop?
AnuragSrivastava272
 
PPTX
Introduction to VB.NET - UP SITF
John Patrick Oliveros
 
Do...until loop structure
Jd Mercado
 
Java Repetiotion Statements
Huda Alameen
 
Loop
kuldeep94
 
nuts and bolts of c++
guestfb6ada
 
Java input Scanner
Huda Alameen
 
Looping statement in vb.net
ilakkiya
 
What is while loop?
AnuragSrivastava272
 
Introduction to VB.NET - UP SITF
John Patrick Oliveros
 

Similar to Do...Loop (20)

PPTX
While , For , Do-While Loop
Abhishek Choksi
 
PDF
cpu.pdf
RAJCHATTERJEE24
 
DOCX
Loops and iteration.docx
NkurikiyimanaGodefre
 
PDF
OIT 116 LOOPS AND CONDITION STATEMENTS.pdf
Carlos701746
 
PPTX
CONTROL STRUCTURE IN VB
classall
 
PDF
Loops and conditional statements
Saad Sheikh
 
PPTX
Lecture 5
Mohammed Khan
 
PPTX
Chapter 5.1
sotlsoc
 
PPTX
Loops in c
RekhaBudhwar
 
PPTX
Loops c++
Shivani Singh
 
PDF
Flow control in c++
Subhasis Nayak
 
PDF
Loop and while Loop
JayBhavsar68
 
PPT
15-Loops.ppt
harshsolankurephotos
 
PPTX
Introduction& Overview-to-C++_programming.pptx
divyadhanwani67
 
PPTX
Introduction to C++ programming language
divyadhanwani67
 
PDF
C++ control structure
bluejayjunior
 
PPT
Visula C# Programming Lecture 4
Abou Bakr Ashraf
 
PPTX
Loops in c language
tanmaymodi4
 
PPTX
Loops in c language
Tanmay Modi
 
PDF
Control statements
Kanwalpreet Kaur
 
While , For , Do-While Loop
Abhishek Choksi
 
Loops and iteration.docx
NkurikiyimanaGodefre
 
OIT 116 LOOPS AND CONDITION STATEMENTS.pdf
Carlos701746
 
CONTROL STRUCTURE IN VB
classall
 
Loops and conditional statements
Saad Sheikh
 
Lecture 5
Mohammed Khan
 
Chapter 5.1
sotlsoc
 
Loops in c
RekhaBudhwar
 
Loops c++
Shivani Singh
 
Flow control in c++
Subhasis Nayak
 
Loop and while Loop
JayBhavsar68
 
15-Loops.ppt
harshsolankurephotos
 
Introduction& Overview-to-C++_programming.pptx
divyadhanwani67
 
Introduction to C++ programming language
divyadhanwani67
 
C++ control structure
bluejayjunior
 
Visula C# Programming Lecture 4
Abou Bakr Ashraf
 
Loops in c language
tanmaymodi4
 
Loops in c language
Tanmay Modi
 
Control statements
Kanwalpreet Kaur
 
Ad

More from Muhammad Al Fatih (6)

PDF
FINAL-SMARTSPOUSE
Muhammad Al Fatih
 
PDF
ppt_fp-pwl2015
Muhammad Al Fatih
 
PDF
Internet Advantages
Muhammad Al Fatih
 
PDF
alfaPAPER Presentation
Muhammad Al Fatih
 
PDF
Agile Development
Muhammad Al Fatih
 
PDF
10 Reasons to Public School
Muhammad Al Fatih
 
FINAL-SMARTSPOUSE
Muhammad Al Fatih
 
ppt_fp-pwl2015
Muhammad Al Fatih
 
Internet Advantages
Muhammad Al Fatih
 
alfaPAPER Presentation
Muhammad Al Fatih
 
Agile Development
Muhammad Al Fatih
 
10 Reasons to Public School
Muhammad Al Fatih
 
Ad

Do...Loop

  • 2. USE Use a Do…Loop to execute a block of statements an indefinite number of times. There are several variations of the Do...Loop statement, but each evaluates a numeric condition to determine whether to continue execution. As with If...Then, the condition must be a value or expression that evaluates to False (zero) or to True (nonzero). Do…Loop }
  • 3. In the following Do...Loop, the statements execute as long as the condition is True: Do While condition statements Loop When Visual Basic executes this Do…Loop, it first tests condition. If condition is False (zero), it skips past all the statements. If it's True (nonzero), Visual Basic executes the statements and then goes back to the Do…While statement and tests the condition again. Example : Dim sum As Integer = 0 Dim counter As Integer = 0 Do While sum < 100 sum = sum + CInt(Textbox1.Text) counter = counter + 1 Loop MsgBox("The loop has run " & CStr(counter) & " times!")
  • 4. Another variation of the Do...Loop statement executes the statements first and then tests condition after each execution. This variation guarantees at least one execution of statements: Do statements Loop While condition Example : Dim sum As Integer = 0 Dim counter As Integer = 0 Do sum = sum + CInt(Textbox1.Text) counter = counter + 1 Loop While sum < 100 MsgBox("The loop has run " & CStr(counter) & " times!")
  • 5. Term Definition Do Starts the definition of the Do loop. While Repeat the loop until condition is False. Until Repeat the loop until condition is True. condition Boolean expression. If condition is Nothing, Visual Basic treats it as False. statements One or more statements that are repeated while, or until, condition is True. Continue Do Transfers control to the next iteration of the Do loop. Exit Do Transfers control out of the Do loop. Loop Terminates the definition of the Do loop. You can use either While or Until to specify condition, but not both.
  • 6. * The above example will keep on adding until counter > 1000. The above example can be rewritten as : Do while counter <= 1000 num.Text = counter counter = counter + 1 Loop Example : Do num.Text = counter counter = counter + 1 Loop Until counter > 1000