Dale - Computer Science Illuminated 274

Dale - Computer Science Illuminated 274 - tests the...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
8.3 Functionality of Imperative Languages 247 Figure 8.4 Flow of control of while statement true false Boolean expression Next statement or sequence of statements Statement or sequence of statements use of a special variable called a loop control variable . The first part is initialization: The loop control variable is initialized to some starting value. The second part is testing: Has the loop control variable reached a predetermined value? The third part is incrementation: The loop control variable is incremented by one. The following algorithm repeats a process limit times. count is the loop control variable. It is set to 1 outside the loop. The while
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: tests the expression count <= limit and executes the loop body as long as the expression is true. The last statement in the loop increments the loop control variable count . How many times does the loop execute? The loop executes when count is 1, 2, 3, . .. limit . So the loop executes limit times. The initial value of the loop control variable and the relational operator used in the Boolean expression determine the number of times the loop executes. Set count to 1 Initialize count to 1 While (count <= limit) Test ... Body of the loop Set count to count + 1 Increment ... Statement(s) following loop...
View Full Document

This note was uploaded on 01/13/2011 for the course CSE 1550 taught by Professor Marianakant during the Fall '10 term at York University.

Ask a homework question - tutors are online