Gentee Programming Language > Documentation > Syntax | Download documentation |
The switch statement enables the execution of one or more statements, that is subject to the specified expression's value. After the keyword, the primary expression follows, which is evaluated and is stored as a switch-value. Then the switch-block appears; unlike the general block, this block contains labels label, the case and default statements.
<switch> ::= switch <expression>'{' {case <expression> {','<expression>} {<label>} <block>} [default {<label>} <block>] '}'
The case statement is followed by expressions separated by commas and the case statement body, which will be executed if any expression equals the switch-value. Transfer of control to the end of the switch statement after the case block execution is complete. The expressions located in the case statement are evaluated and compared for equality sequentially. If all expressions do not equal the switch-value, then control is transferred to the next case or default statement. The default statement does not have any expression lists; nevertheless, if none of the case values matches expression, the default block is executed. The default statement can appear only once and should come after all case statements.
switch a & 0x0f
{
case 0x01, 0x02
{
b = 10
}
case 0x03
{
b = 100
}
case 0x04, k & 0x0f // The case expression is not required to be a constant
{
b = 1000
}
default
{
b = 0
}
}
Labels that appear after the case keyword enable you to enter the appropriate case case-block from another case-block.
switch a
{
case 0
label a0
{
c = 1
}
case 1
{
if b
{
goto a0
}
c = 2
}
}
See also
The label and goto Instructions
![]() |
![]() Copyright © 2004-2006 Gentee Inc. All rights reserved. ![]() |