0% found this document useful (0 votes)
126 views

Switch Statement - Statements - Syntax - C++ Now

Switch statement provides a selection control structure to execute a selected section of code determined by the run-time value of an expression. Condition is an expression which evaluates to an integer value, which include signed, unsiened, char, enum, and even boolean values. Switch statement is used to provide a multiway selection, based on an integral value.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
126 views

Switch Statement - Statements - Syntax - C++ Now

Switch statement provides a selection control structure to execute a selected section of code determined by the run-time value of an expression. Condition is an expression which evaluates to an integer value, which include signed, unsiened, char, enum, and even boolean values. Switch statement is used to provide a multiway selection, based on an integral value.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

7/11/12

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

switch Statement - Statements - Syntax - C++ Now

::= <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

switch Statement - Statements - Syntax - C++ Now

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

<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

copy right 2009-2008, J.H.Y oung, last modif ied 06/24/2012

cpp.comsci.us/syntax/statement/switch.html

3/3

You might also like