Repetition: Chapter 6 - Visual Basic Schneider 1
Repetition: Chapter 6 - Visual Basic Schneider 1
Repetition
No
Is the condition true
Yes
Execute statements
within
the loop
Execute statements
that follow the loop
Event-controlled loops
repeat until something happens in the loop body to change
the value of loop control variable.
passWord = ""
Do While passWord <> "SHAZAM"
passWord = UCase(InputBox("What is the password?"))
Loop
Example:
Open “PHONE.TXT” for Input As #1
Do While Not EOF(1)
Input #1, nom, phoneNum
picOutput.Print nom, phoneNum
Loop
Close #1
Next i
End Sub
Output: 1 3 5
Chapter 6 - Visual Basic Schneider 26
When a For statement is
encountered
1. The control variable is assigned the initial
value.
2. After each loop iteration, the step value is
added to the value of the control variable.
(If there is no step value, 1 is added.)
3. Iteration continues until the terminating
value is exceeded.
Output: **********
Chapter 6 - Visual Basic Schneider 29
Example
Private Sub cmdDisplay_Click()
Dim i As Integer, stars As Integer
stars = Val(InputBox("Row length (1-20) : "))
For i = 1 To stars
picOutput.Print "*";
Next i
End Sub
Output: 8 6 4 2