Presentation is loading. Please wait.

Presentation is loading. Please wait.

Do Loops A Do..Loop terminates based on a condition that is specified Execution of a Do..Loop continues while a condition is True or until a condition.

Similar presentations


Presentation on theme: "Do Loops A Do..Loop terminates based on a condition that is specified Execution of a Do..Loop continues while a condition is True or until a condition."— Presentation transcript:

1 Do Loops A Do..Loop terminates based on a condition that is specified Execution of a Do..Loop continues while a condition is True or until a condition is True The condition can be placed at the Top or at the Bottom of the loop Align the Do and Loop statements with each other and indent the lines of code to be repeated in the body of the loop

2 Checking the condition before entering the loop: Do {While / Until} Condition ‘statements in the loop Loop Testing for completion at the top of the loop Also known as a pretest The statements inside the loop may never be executed if the terminating condition is True, the first time it is tested iTotal = 0 Do Until iTotal = 0 ‘statements in the loop Loop

3 Checking the condition after one iteration of the loop: Do ‘statements in the loop Loop {While / Until} Condition Testing for completion at the bottom of the loop Also known as a posttest The statements inside the loop will always be executed at least once iTotal = 0 Do ‘statements in the loop Loop Until iTotal = 0

4

5

6

7

8

9

10

11

12 Example Code a procedure that prompts the user for a password to login. If the password is not greater then 5 characters then a message is displayed to the user. The user is allowed 3 attempts to login, if unsuccessful at this point the application shuts down

13 Example Code a procedure that checks 5 times whether the username is of a certain length (in this case greater then 10 characters). After the fifth attempt the user is locked out of the application.

14

15

16

17

18


Download ppt "Do Loops A Do..Loop terminates based on a condition that is specified Execution of a Do..Loop continues while a condition is True or until a condition."

Similar presentations


Ads by Google