Loops and Conditions - The do statement

Chapter chap5 section 9

The while statement may be described as test-before-execute . If the controlling expression is initially zero then the controlled statement is never executed. There is an alternative version that is sometimes useful. This is the do statement which may be described as execute-before-test . This is sometimes called a one-trip-loop referring to the fact that the loop "body" is always executed at least once. The syntax is

do <statement> while (<expression>) ;

The controlled statement is always executed at least once. It is sometimes useful in interactive programs where the user must provide some input and there is no sensible initial setting.


The trinary (?:) operator