switch command (C and C++)

The switch command enables you to transfer control to different commands within the switch body, depending on the value of the switch expression. The switch, case, and default keywords must be lowercase and cannot be abbreviated.

Read syntax diagramSkip visual syntax diagram
>>-switch--(--expression--)--{--| switch_body |--}--;----------><

switch_body

|--+---------------------+--| default_clause |------------------>
   | .-----------------. |                       
   | V                 | |                       
   '---| case_clause |-+-'                       

>--+---------------------+--------------------------------------|
   | .-----------------. |   
   | V                 | |   
   '---| case_clause |-+-'   

case_clause

|--case--case_expression--:--+-------------+--------------------|
                             | .---------. |   
                             | V         | |   
                             '---command-+-'   

default_clause

|--+-----------------------------+------------------------------|
   '-default--:--+-------------+-'   
                 | .---------. |     
                 | V         | |     
                 '---command-+-'     

expression
A valid Debug Tool C expression.
case_expression
A valid character or optionally signed integer constant.
command
A valid Debug Tool command.

The value of the switch expression is compared with the value of the expression in each case clause. If a matching value is found, control is passed to the command in the case clause that contains the matching value. If a matching value is not found and a default clause appears anywhere in the switch body, control is passed to the command in the default clause. Otherwise, control is passed to the command following the switch body.

If control passes to a command in the switch body, control does not pass from the switch body until a break command is encountered or the last command in the switch body is performed.

Usage notes

Examples