Dale - Computer Science Illuminated 273

# Dale - Computer Science Illuminated 273 - a loop is...

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

246 Chapter 8 High-Level Programming Languages The value stored in variable operator is compared with the symbol on each successive line. When a match if found, the statement on the other side of the colon is executed and control passes to the statement following the case statement. If there is no match, none of the statements are executed. Because the case is not necessary, we do not examine how it is translated into a specific language. Looping Statements We introduced the concept of repeating a sequence of statements in Chapter 6. The subalgorithm that we repeated earlier in this chapter has the expression: The processing is repeated until all the names have been processed. That is, the sequence of statements is repeated as long as the expression is true. When the expression becomes false, the processing continues with the statements immediately following the loop. We used indentation in the algorithm to show the statements included in the loop. Later we show how
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: a loop is implemented in Ada, VB.NET, C++, and Java. A while statement, like an if statement, alters the normal sequential flow of a program. The behavior is described in Figure 8.4. Note that an if statement is used to make a choice between two courses of action; the while statement is used to repeat a course of action. Before we look at how different high-level languages express the while statement, lets look at two distinct types of repetitions. Count-controlled loops A count-controlled loop is one that repeats a specified number of times. The looping mechanism simply counts each time the process is repeated, then tests to see if its finished before begin-ning again. There are three distinct parts to this kind of loop, which makes While (there are more names) CASE operator OF + : Set answer to one + two - : Set answer to one two * : Set answer to one * two / : Set answer to one / two...
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