SlideShare a Scribd company logo
1 of 7
Download to read offline
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

Similar to Do...Loop

Chapter 5.1
Chapter 5.1Chapter 5.1
Chapter 5.1
sotlsoc
 
C++ control structure
C++ control structureC++ control structure
C++ control structure
bluejayjunior
 

Similar to Do...Loop (20)

While , For , Do-While Loop
While , For , Do-While LoopWhile , For , Do-While Loop
While , For , Do-While Loop
 
cpu.pdf
cpu.pdfcpu.pdf
cpu.pdf
 
Loops and iteration.docx
Loops and iteration.docxLoops and iteration.docx
Loops and iteration.docx
 
CONTROL STRUCTURE IN VB
CONTROL STRUCTURE IN VBCONTROL STRUCTURE IN VB
CONTROL STRUCTURE IN VB
 
Loops and conditional statements
Loops and conditional statementsLoops and conditional statements
Loops and conditional statements
 
Lecture 5
Lecture 5Lecture 5
Lecture 5
 
Chapter 5.1
Chapter 5.1Chapter 5.1
Chapter 5.1
 
Loops in c
Loops in cLoops in c
Loops in c
 
Loops c++
Loops c++Loops c++
Loops c++
 
Flow control in c++
Flow control in c++Flow control in c++
Flow control in c++
 
Loop and while Loop
Loop and while LoopLoop and while Loop
Loop and while Loop
 
15-Loops.ppt
15-Loops.ppt15-Loops.ppt
15-Loops.ppt
 
C++ control structure
C++ control structureC++ control structure
C++ control structure
 
Visula C# Programming Lecture 4
Visula C# Programming Lecture 4Visula C# Programming Lecture 4
Visula C# Programming Lecture 4
 
Loops in c language
Loops in c languageLoops in c language
Loops in c language
 
Loops in c language
Loops in c languageLoops in c language
Loops in c language
 
Control statements
Control statementsControl statements
Control statements
 
Flow of control C ++ By TANUJ
Flow of control C ++ By TANUJFlow of control C ++ By TANUJ
Flow of control C ++ By TANUJ
 
Loops Basics
Loops BasicsLoops Basics
Loops Basics
 
whileloop-161225171903.pdf
whileloop-161225171903.pdfwhileloop-161225171903.pdf
whileloop-161225171903.pdf
 

More from Muhammad Al Fatih

More from Muhammad Al Fatih (6)

FINAL-SMARTSPOUSE
FINAL-SMARTSPOUSEFINAL-SMARTSPOUSE
FINAL-SMARTSPOUSE
 
ppt_fp-pwl2015
ppt_fp-pwl2015ppt_fp-pwl2015
ppt_fp-pwl2015
 
Internet Advantages
Internet AdvantagesInternet Advantages
Internet Advantages
 
alfaPAPER Presentation
alfaPAPER PresentationalfaPAPER Presentation
alfaPAPER Presentation
 
Agile Development
Agile DevelopmentAgile Development
Agile Development
 
10 Reasons to Public School
10 Reasons to Public School10 Reasons to Public School
10 Reasons to Public School
 

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