Repetition Structures - PowerPoint PPT Presentation

1 / 8
About This Presentation
Title:

Repetition Structures

Description:

'Display the numbers from 1 to 10. num = 1. Do While num = 10 ... Dim balance As Single, numYears As Integer 'Compute years required to become a millionaire ... – PowerPoint PPT presentation

Number of Views:15
Avg rating:3.0/5.0
Slides: 9
Provided by: scie248
Learn more at: http://www.cs.uwyo.edu
Category:

less

Transcript and Presenter's Notes

Title: Repetition Structures


1
Repetition Structures
  • Do...Loop Statement

2
Do...Loop Statement
  • Do While Until condition
  • statements
  • Exit Do
  • statements
  • Loop

3
Do...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
4
Do...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
5
Private 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
6
Do...Loop Statement
  • Do
  • statements
  • Exit Do
  • statements
  • Loop While Until condition

7
Do...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
8
Nested 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
Write a Comment
User Comments (0)
About PowerShow.com