next up previous contents
Next: Conditional CYCLE Up: More on DO Loops Previous: More on DO Loops   Contents

Conditional EXIT

do
  $\langle exec\_stmts_1 \rangle$ 
  if ( $\langle logical\_expr \rangle$ ) exit
  $\langle exec\_stmts_2 \rangle$  
end do

The ession is evaluated at every sweep through the loop. If true, EXIT is executed, which (of course!) exits the loop and transfers control to the first statement after END DO. Usually, EXIT is in either the first or the last statement in the body of the loop, for improved readability. An EXIT statement outside the body of a loop is an error.

Conditional EXIT loops are useful when we want the input data to control the number of iterations. For example, the Fahrenheit to Celsius program can read and convert temperatures until an unrealistic temperature, say or less, is read in. Try this example!



Adrian Sandu 2001-08-26