Unit II - Determinate and Indeterminate Loops
Unit II - Determinate and Indeterminate Loops
• Syntax
For counter=startNumber to endNumber (Step increment)
One or more VB statements
Next
The For...Next Loop Contd…
Example 1
• The following loop prints the numbers from 1 to 100:
Dim x As Integer
For x = 1 To 50
Print x
Next
Example 2
• The following loop prints the numbers from 1 to 50 in steps of 2.
Dim x as integer
For x = 1 To 50 Step 2
Print x
Next
Example 3
• The following loop prints the numbers from 1000 to 5 in steps of -5.
Dim counter as integer
For counter=1000 to 5 step -5
Print counter
next