1 / 18

Testing for completion at the top of the loop Also known as a pretest

gary-boyer
Download Presentation

Testing for completion at the top of the loop Also known as a pretest

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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

  2. 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

  3. 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

  4. 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

  5. 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.

More Related