Looping
Looping
Looping
This is an important programming technique to repeat some command until the specified
condition is met.
1. For…Next Loop
Format :
For variable_Name = startNumber to endNumber (Step increment)
One or more Visual Basic statements
Next
To exit a For...Next Loop, you can place the Exit For statement within the loop.
2. Do Loop
Format 1.
Do While condition
Block of one or more Visual Basic statements
Loop
Format 2.
Do
Block of one or more Visual Basic statements
Loop While condition
Format 3.
Do Until condition
Block of one or more Visual Basic statements
Loop
Format 4.
Do
Block of one or more Visual Basic statements
Loop Until condition
Exercise:
1. Write code to generate the following number series using the above each formats.
(a) 5 10 15 20 25
(b) 10 7 4 1
2. Write a program to find the sum of all multiples of 6 from 10 to 50.