C++ Logic Flow Control

IF Statement

Syntax

IF (condition)
   {statements}
ELSE
   {statements}

Notes

The ELSE clause is optional

SWITCH Statement

Syntax

SWITCH (expression) 
    { 
    CASE const1: statements; 
                 BREAK; 
    CASE const2: 
    CASE const3: statements; 
                 BREAK; 
    DEFAULT: statements; 
    }

Notes


FOR Loop

Syntax

FOR (InitExpr; TestExpr; IncrExpr)
   {
       LoopStmts;
   }

Notes


WHILE Loop

Syntax

WHILE (condition)
   {
       LoopStmts;
   }

Notes

Uses the BREAK and CONTINUE statements in the same way as a FOR loop

DO-WHILE Loop

Syntax

DO
   {
   LoopStmts;
   } WHILE (condition);

Notes

Uses the BREAK and CONTINUE statements in the same way as a FOR loop