Using Loop Statements
Do.. Loop Statement
Do...Loop: Repeats a block of statements while a condition is True or until a condition becomes True.
Syntax:
Do [{While | Until} condition]
[statements]
[Exit Do]
[statements]
Loop
OR
Do
[statements]
[Exit Do]
[statements]
Loop [{While | Until} condition]
Examples 1
Example 2
Example 3
Example 4
Do.. Loop Statement
Do...Loop: Repeats a block of statements while a condition is True or until a condition becomes True.
Syntax:
Do [{While | Until} condition]
[statements]
[Exit Do]
[statements]
Loop
OR
Do
[statements]
[Exit Do]
[statements]
Loop [{While | Until} condition]
Examples 1
Do...Loop Counter = 1 Do While Counter < 4 Total =Inputbox("Please enter the total marks in numbers") If Total < 50 Then MsgBox "Fail" ElseIf Total >=50 and Total <=60 then Msgbox "Second Class" ElseIf Total >60 and Total <80 then Msgbox "First Class" ElseIf Total >=80 then Msgbox "Distinction" Else Msgbox "Invalid Marks" End If Counter = Counter + 1 Loop
Example 2
Counter = 1 Do Total =Inputbox("Please enter the total marks in numbers") If Total < 50 Then MsgBox "Fail" ElseIf Total >=50 and Total <=60 then Msgbox "Second Class" ElseIf Total >60 and Total <80 then Msgbox "First Class" ElseIf Total >=80 then Msgbox "Distinction" Else Msgbox "Invalid Marks" End If Counter = Counter + 1 Loop until Counter > 4
Example 3
'Exit Do While loop Do While Counter < 10 Counter=counter + 1 If counter = 6 Then Exit Do End If MsgBox Counter Loop
Example 4
'Exit Do Until loop Do Counter=Counter + 1 If Counter = 6 Then Exit Do End If MsgBox Counter Loop Until counter >11