Page 144 - Open Soource Technologies 304.indd
P. 144
Event Driven Programming
Execute
statements
within
the loop?
No Is the
Do condition
statement (s) true?
Loop Until condition is true
Yes
Execute
statements
that follow
the loop
Figure 6.3: Pseudocode and Flowchart for a Do loop with Condition Tested at the Bottom.
3: The following program is equivalent to Example 12, except that the condition
is tested at the bottom of the loop:
Private Sub btnDisplay_Click(...) Handles btnDisplay.Click
Dim response As Integer, quotation As String = “”
Do
response = CInt(InputBox(“Enter a number from 1 to 3.”))
Loop Until (response >= 1) And (response <= 3)
Select Case response
Case 1
quotation = “Plastics.”
Case 2
quotation = “Pardip.”
Case 3
quotation = “That’s all folks.”
End Select
txtQuotation.Text = quotation
End Sub
Do loops allow us to calculate useful quantities for which we might not know a simple formula.
4: Suppose you deposit money into a savings account and let it accumulate at
six percent interest compounded annually. The following program
determines when you will be a millionaire:
138 LOVELY PROFESSIONAL UNIVERSITY