Professional Documents
Culture Documents
Lecture Outline
SWE1301: Introduction to Problem
Solving and Software Development • Loop Logic Structure
• While loop
• Do-loop
Do while loop Structure • While loop is often used for input validation;
• checking input data for errors.
1
2/1/2022
Step 4 : Stop
2
2/1/2022
Step 4: Stop
3
2/1/2022
Step 1: Assign i = 1
Step 2 : (i <6) repeat
print i
Compute i = i +1
Step 3: End
• unlike the while loop, the do…while loop has The while loop executes as
its test at the end of the loop rather than at the follow:
Step 1: The loop body is
beginning.
executed.
Step 2: Then the loop
expression/condition is
• Do-loop body is executed at least once.
evaluated, If loop
condition is TRUE, Repeat
step (1) until the loop
condition evaluates to
FALSE.
4
2/1/2022
5
2/1/2022
6
2/1/2022
Exercises Exercises
5. The Kudi Zalla ATM works as follows:
4. You want to write a FOR loop that displays “I love • Entry process: Immediately a user slots a card into the machine,
to program!” 50 times. s/he is prompted to enter a pin. The user stays in the entry process
until a correct pin is entered.
• The Selection process: Once a correct pin is entered the user can
i. What initialization expression will you use? perform any of the three (3) transactions namely withdrawal,
transfer or checking balance. If the user selects the withdrawal
ii. What test expression will you use? option, the ATM displays “Enter the amount required”. Once a valid
iii. What update expression will you use? amount is entered the ATM dispenses the cash and displays “Please
take your cash”. If the user however selects the transfer option, the
iv. Write the loop ATM displays “Enter the destination bank, the destination account
number and the amount to transfer”. It then displays “Transfer
successful” if all the details are correct. If the user, on the other
hand, selects the checking balance option, the ATM displays the
balance in the form “Your balance is XXXXXX”.
• Exit Process: At the end of any of the selected options, the ATM
displays “Do you want to perform another transaction, yes or no?” If
the user replies with a yes, the program will go back to the entry
process; otherwise the user is given back his/her card.
SWE1301_Introduction to Problem Solving and Software SWE1301_Introduction to Problem Solving and Software
27 28
Development Development
7
2/1/2022
Exercises
5. Continues