1.4. Writing Conditional and Loop Statements

By default, statements are executed once in sequence, beginning with the first statement of main(). In the preceding section, we had a peek at the if statement. The if statement allows us to execute conditionally one or a sequence of statements based on the truth evaluation of an expression. An optional else clause allows us to test multiple truth conditions. A looping statement allows us to repeat one or a sequence of statements based on the truth evaluation of an expression. The following pseudo-code program makes use of two looping statements (#1 and #2), one if statement (#5), one if-else statement (#3), and a second conditional statement called a switch statement (#4).

 // Pseudo code: General ...

Get Essential C++ now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.