A Do loop repeatedly executes a block of statements either as long as or until a certain condition is true. The condition can be checked either at the top of the loop or at the bottom. There are two different ways that you can do the Do loop. It first can be done by putting While after the Do.
Dim num As Integer = 1
Do While num <= 7
MessageBox.Show(num)
num += 1
Loop
The second Do can be done by putting the While after the Loop.
Dim num As Integer = 1
Do
MessageBox.Show(num)
num += 1
Loop While num <= 7
A For...Next loop repeats a block of statements a fixed number of times. The counter variable assumes an initial value and increases it by one after each pass through the loop until it reaches the terminating value. Alternative increment values can be specified with the Step keyword.
'Displays in a message box the first five numbers and their square roots.
'I also used the step keyword to skip step 2. So it will skip 2 4.
For i As Integer = 1 To 5 Step 2
MessageBox.Show(i & " " & i ^ 2)
Next
A For Each loop repeats a group of statements for each element in an array.
Dim i As Integer = 500
For Each number As Integer In New Long() {50, 15, 32}
MessageBox.Show(number & " ")
Next
No comments:
Post a Comment