Title: Repetition Structures
1Repetition Structures
2Do...Loop Statement
- Do While Until condition
- statements
- Exit Do
- statements
- Loop
3Do...Loop Example
Private Sub cmdDisplay_Click() Dim num As
Integer 'Display the numbers from 1 to 10 num
1 Do While num lt 10 picNumbers.Print
num num num 1 Loop End Sub
4Do...Loop Example
Private Sub cmdDisplay_Click() Dim x As
Integer, y As Integer x 1 y x x Do
While y lt 100 picOutput.Print y x
x 1 y x x Loop End Sub
5Private Sub cmdYears_Click() Dim balance As
Single, numYears As Integer 'Compute years
required to become a millionaire picWhen.Cls
balance Val(txtAmount.Text) numYears 0 Do
While balance lt 1000000 balance balance
0.07 balance numYears numYears 1
Loop picWhen.Print "In" numYears "years you
will have a _ million dollars." End Sub
6Do...Loop Statement
- Do
- statements
- Exit Do
- statements
- Loop While Until condition
7Do...Loop Example
Private Sub cmdEstimate_Click() Dim amt As
Single, yrs As Integer amt 15000 yrs 0
Do amt amt 1.05 - 1000 yrs yrs
1 Loop Until amt lt 0 picResult.Print "It
takes" yrs "years to _ deplete the
account." End Sub
8Nested Do...Loop Example
- Do
- Do While Counter lt 20
- Counter Counter 1
- If Counter 10 Then
- Check False Exit Do
- End If
- Loop
- Loop Until Check False