LOOPS
LOOPS
VB
DEFINITION
• While condition(s)
• [statements 1]
• [statements 2] ...
• [statements n]
• Wend
• OR
• While condition
• [expression or statements]
• Wend
FLOW CHART
Example 1 Printing numbers from 1
to 1000
PROGRAM EXAMPLE
• number = 1
• While number <= 10
• Print number
• number = number + 1
• Wend
• End Sub
Do until/loop repetition control
structure
• Do
• Block of one or more VB statements
• Loop Until condition
FLOW CHART-DO UNTIL
example
• number = number + 1
• Print number
• Loop
• End Sub
Alternate Syntax
• The alternate syntax for Do...Until loop which checks the condition at
the end of the loop.
• Do
• [statement (s)]
• Loop Until condition
• It checks the condition at the end of the loop. The statements inside
the loop are executed at least once, even if the condition is True.
Flow chart
Example
• End Sub
Do------while loop
• Do while <conditions>
• Statements
• Loop
• Syntax
Do
Statements(s)
While (condition)
Do loop while
example
• End Sub
With Statement
• With Text1
• .Width = 2500
• .Height = 800
• .ForeColor = vbRed
• .Text = "NotesforMsc"
• End With
• End Sub
•For next loop
For next loop
• End Sub
Find the summation of number from 1 to 10
• Exit For
• End If
• Print number
• Next
USING STEP KEYWORD
Next
End Sub
Sum of even numbers
Next
End Sub
Program that steps the for loop