Switch Statement - Statements - Syntax - C++ Now
Switch Statement - Statements - Syntax - C++ Now
C++ Now
Home Syntax
C++ Syntax
switch Statement
Statements switch
Abstract
The switch statement provides a selection control structure to execute a selected section of code determined by the run-time value of an expression. The condition is an expression which evaluates to a integer value, which include signed, unsiened, char, enum, and even boolean values. Selection statements are also referred to as conditional statements. Other C++ selection statements are the if statement and the if-else statement.
Usage
The switch statement is used to provide a multiway selection, based on an integral value.
Syntax
Syntax Diagrams
BNF switch-statement ::= 'switch' '(' <dynamic-expression> ')' '{' <declaration-list> <statement-list> <caselist> '}' case-list ::= <case> ::= <case-list> <case> case ::= <case-label-list> <statement-list> case-label ::= 'case' <static-expression> ':' ::= 'default' ':' dynamic-expression ::= <expression> static-expression
cpp.comsci.us/syntax/statement/switch.html 1/3
7/11/12
::= <expression> statement-list ::= <empty> ::= <statement> ::= <statement> <statement-list> declaration-list ::= <declaration> ::= <declaration> <declaration-list> ::= <empty> EBNF switch-statement ::= 'switch' '(' <dynamic-expression> ')' '{' <declaration> * <statement> * <case> * '}' case ::= <case-label> * <statement> * case-label ::= 'case' <static-expression> ':' ::= 'default' ':' dynamic-expression ::= <expression> static-expression ::= <expression>
Flowchart
Example
#nld <otemh icue isra.> itmi ( { n an ) itCut n on; Cut=2 on ; sic (on){ wth Cut cs 0 ae :
cpp.comsci.us/syntax/statement/switch.html 2/3
7/11/12
cu < "oe\" ot < Nn.n; bek ra; cs 1 ae : cu < "nyoe\" ot < Ol n.n; bek ra; cs 2 ae : cu < " pi.n; ot < A ar\" bek ra; cs 3 ae : cu < "he.n; ot < Tre\" bek ra; dfut eal: cu < "ay\" ot < Mn.n; bek ra; } rtr 0 eun ; }
Output
Api. ar
Reference Links
Break Statement Statement Expression
Other Languages
C Now C++ Now Java Now Pascal Now PHP Now Home Syntax
C Switch Statement C++ Switch Statement Java Switch Statement Pascal Case Statement PHP Switch Statement
Statements switch
cpp.comsci.us/syntax/statement/switch.html
3/3