Jasinski Technical Wiki

Navigation

Home Page
Index
All Pages

Quick Search
»
Advanced Search »

Contributor Links

Create a new Page
Administration
File Management
Login/Logout
Your Profile

Other Wiki Sections

Software

PoweredBy

C++ Logic Flow Control

RSS
Modified on Sun, Jan 25, 2009, 10:21 PM by Administrator Categorized as C and C-plus-plus

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

  • The BREAK statements are optional
  • The DEFAULT clause is optional

FOR Loop

Syntax

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

Notes

  • InitExpr is optional, and executed only before the first pass
  • TestExpr is optional. If omitted, is is always TRUE, and the only way to exit the loop is with a BREAK statement
  • TestExpr is tested for truth before EVERY pass
  • IncrExpr is executed after EVERY pass
  • LoopStmts are optional
  • All three expressions can contain multiple statements separated by commas. Only the last statement in TextExpression affects execution
  • Within the loop the CONTINUE statement will skip the rest of the current iteration and continue with the next.

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

ScrewTurn Wiki version 3.0.1.400. Some of the icons created by FamFamFam. Except where noted, all contents Copyright © 1999-2024, Patrick Jasinski.