5.2) If Statements: Two Branches
Flow of Control
Example
if (x < 0) { cout << "x is negative" << endl; exit(1); } else { // Do calculation with x here } // Continue with program here
Key Points
else
clause executes only if test evaluates tofalse
- When
else
clause contains a single statement the{}
can be omitted