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
PDF
Java Repetiotion Statements
PPTX
Loop
PDF
nuts and bolts of c++
PDF
Java input Scanner
PPTX
Looping statement in vb.net
PPTX
What is while loop?
PPTX
Introduction to VB.NET - UP SITF
Do...until loop structure
Java Repetiotion Statements
Loop
nuts and bolts of c++
Java input Scanner
Looping statement in vb.net
What is while loop?
Introduction to VB.NET - UP SITF

Similar to Do...Loop (20)

PPTX
Looping statements
PDF
VB PPT by ADI PART3.pdf
PDF
VB PPT by ADI PART3.pdf
PPT
Ppt lesson 10
PPTX
Vb.net (loop structure)
PPTX
CONTROL STRUCTURE IN VB
PPT
PPTX
Advanced VB: Review of the basics
PPTX
Advanced VB: Review of the basics
PPTX
Loop structures chpt_6
PPTX
VB(unit1).pptx
PPTX
BSc. III Unit iii VB.NET
PPT
Arrays
PPT
Vb scripting
PPT
30,31,32,33. decision and loop statements in vbscript
PDF
Conditional Statements & Loops
PPTX
Presentation on visual basic 6 (vb6)
DOC
Conditional statements in vb script
PDF
Loops in Visual Basic Programming
PPTX
Unit IV Array in VB.Net.pptx
Looping statements
VB PPT by ADI PART3.pdf
VB PPT by ADI PART3.pdf
Ppt lesson 10
Vb.net (loop structure)
CONTROL STRUCTURE IN VB
Advanced VB: Review of the basics
Advanced VB: Review of the basics
Loop structures chpt_6
VB(unit1).pptx
BSc. III Unit iii VB.NET
Arrays
Vb scripting
30,31,32,33. decision and loop statements in vbscript
Conditional Statements & Loops
Presentation on visual basic 6 (vb6)
Conditional statements in vb script
Loops in Visual Basic Programming
Unit IV Array in VB.Net.pptx
Ad

More from Muhammad Al Fatih (6)

PDF
FINAL-SMARTSPOUSE
PDF
ppt_fp-pwl2015
PDF
Internet Advantages
PDF
alfaPAPER Presentation
PDF
Agile Development
PDF
10 Reasons to Public School
FINAL-SMARTSPOUSE
ppt_fp-pwl2015
Internet Advantages
alfaPAPER Presentation
Agile Development
10 Reasons to Public School
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