Download SYSdev Programming Manual
Transcript
SECTION 8 HIGH-LEVEL PROGRAMMING ________________________________________________________________________________ 8.6.3 "do while" loop The "do while" loop is similar to the "while" loop, except that the program code is executed before the conditional expression is tested. This guarantees that the program code is executed at least once, whether the conditional expression is true or not. As with the "while" loop, the loop variable(s) must be initialized before the "do while" loop is entered and must be modified inside the program code. General form: do program code while (conditional expression); Evaluation: The program code is executed as long as the conditional expression is true. The program code is executed at least once before the conditional expression is evaluated. The exact sequence of execution is: 1) Execute program code. 2) Test conditional expression for true state. 3) If false: drop out of loop, program execution continues with statements following "do while" loop. 4) If true: go to step (1). Notes: 1) Parenthesis around conditional expression are required. 2) The semicolon ";" following the conditional expression is required. 3) The program code can be either a single line program statement or a statement block as defined in sections 8.3 and 8.4. 4) The "do while" loop does not contain an "init express" or "loop express" as in the "for" loop. The loop variable(s) used in the conditional expression must be initialized before entering the "do while" loop and must be modified inside the program code. 5) The indentation shown on the program code is not required but highly recommended to improve readability. 6) The "do" and "while" keywords are case sensitive, both must be all lower case letters. SYSdev Program Development Manual SYSTEMS Electronics Group - 143 -