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.
- expression
- A valid z/OS® Debugger C expression.
- case_expression
- A valid character or optionally signed integer constant.
- command
- A valid z/OS Debugger 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
- Declarations are not allowed within a
switchcommand. - The
switchcommand does not end with a semicolon. A semicolon after the closing brace is treated as aNullcommand. - Although this command is similar to the
switchstatement in C, it is subject to z/OS Debugger restrictions on expressions. - Duplicate case_expression values are not supported.
- You cannot use the
switchcommand while you replay recorded statements by using thePLAYBACKcommands.
Examples
- The following
switchcommand contains severalcaseclauses and onedefaultclause. Each clause contains a function call and abreakcommand. Thebreakcommands prevent control from passing down through subsequent commands in theswitchbody.Ifkeyhas the value'⁄', theswitchcommand calls the functiondivide. On return, control passes to the command following theswitchbody.char key; printf("Enter an arithmetic operator\n"); scanf("%c",&key); switch (key) { case '+': add(); LIST (key); break; case '-': subtract(); LIST (key); break; case '*': multiply(); LIST (key); break; case '⁄': divide(); LIST (key); break; default: printf("Invalid key\n"); break; } - In the following example,
breakcommands are not present. If the value ofcis equal to 'A', all 3 counters are incremented. If the value ofcis equal to 'a',letteraandtotalare increased. Onlytotalis increased ifcis not equal to 'A' or 'a'.char text[100]; int capa, i, lettera, total; for (i=0; i < sizeof(text); i++) { switch (text[i]) { case 'A': capa++; case 'a': lettera++; default: total++; } }
