180 likes | 289 Views
E N D
Do LoopsA Do..Loop terminates based on a condition that is specifiedExecution of a Do..Loop continues while a condition is True or until a condition is TrueThe condition can be placed at the Top or at the Bottom of the loopAlign the Do and Loop statements with each other and indent the lines of code to be repeated in the body of the loop
Checking the condition before entering the loop:Do {While / Until} Condition‘statements in the loopLoop 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
Checking the condition after one iteration of the loop:Do ‘statements in the loopLoop {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
ExampleCode 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
ExampleCode 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.