Controls - CS 1054 Iteration Controls 1 Iteration causing a...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
CS 1054 Controls Intro to Object-Oriented Dev I Computer Science Dept Va Tech Jan. 2006 ©2006 Barnette, ND 1 Iteration s Iteration causing a set of statements (the body) to be executed repeatedly. Before considering specifics we define some general terms that apply to any iteration construct: When designing a loop, it is important to clearly identify each of these. Understanding the termination condition, and what guarantees it will eventually occur, are particularly vital. pass (or iteration) - one complete execution of the body loop entry - the point where flow of control passes to the body loop test - the point at which the decision is made to (re)enter the body, or not loop exit - the point at which the iteration ends and control passes to the next statement after the loop termination condition - the condition that causes the iteration to stop Controls Intro to Object-Oriented Dev I Computer Science Dept Va Tech Jan. 2006 ©2006 Barnette, ND 2 while Loop s while statement The most versatile loop construct. Syntactically: The Boolean expression is examined before each pass through the body of the loop. If the Boolean expression is true, the loop body is executed; if it is false, execution proceeds to the first statement after the loop body. . while <bool expr> <loop body> The <loop body> can be either a single statement or a compound statement. Semantically: while <bool expr> <loop body> true false
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
CS 1054 Controls Intro to Object-Oriented Dev I Computer Science Dept Va Tech Jan. 2006 ©2006 Barnette, ND 3 while Code s Reserved word while starts the instruction s Parentheses must enclose the <test> s Braces should enclose the <instruction-list>; in the usual way s <test> : The same conditions used in the if instructions s Implementation steps Step 0 : Perform any necessary initialization or setup instructions for the loop Step 1 : Identify the one test that must be true when the task is finished Step 2 : Use the opposite form of the test (negation) Step 3 : Within the while , make progress toward completion of the while Step 4 : Perform any necessary termination or cleanup instructions after the loop to complete solving the problem while ( <test> ) { <instruction-list> } Controls Intro to Object-Oriented Dev I Computer Science Dept Va Tech Jan. 2006
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 8

Controls - CS 1054 Iteration Controls 1 Iteration causing a...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online