< Browse > Home /

Advanced Control Flow – Switch Statements

August 22nd, 2008 | 3 Comments | Posted in C++ by Diego | - [Full Entry]

A switch statement allows you to control the flow of your program similar to if and else statements, but can be easier for the user to understand.

The Switch Statement

The structure of a switch statement is the following:

switch(expression) {
    case <constant_expression>  :
    statements
    break;

    case </constant_expression><constant_expression> :
    statements
    break;

    //More cases…

    default :
    statements
}</constant_expression>

Read more »