Switch statements in ASIL may seem strange. That's because you can vary how much of a comparison is done in the compilation stage.
This is closest to what C++ and C# have.
:::text
switch i%
case 3
' Handle case 3
break ' Fall through not allowed if this case does something
case 5
case 6 ' Fall through allowed because case 5 is empty
' handle cases 5 and 6
break
else ' All other cases
' handle the default case
You don't need to have all the comparisons in a switch be on equality. ASIL allows for an interrupted comparison. In both of the switch statements below, ASIL will put the pieces together.
:::text
switch i%
case < 3
' handle all cases less than 3
break
else
' handle all other cases
switch f% >
case 5
' Handle all cases greater than 5
break
case 3 ' Since the switch started with >, all subsequent cases must be less than the previous case.
else
'Handle all remaining cases
If nothing follows the switch keyword, then each case must have the entire condition.
:::text
switch
case i% < 3
' handle all cases where i% is less than 3
case f# > 3.5
' handle F3 being more than 3.5
else
' handle everything else
Wiki: Commands
Wiki: Home
Wiki: keywords-break
Wiki: keywords-case
Wiki: keywords-else
Wiki: keywords-switch
I considered making switch a complex statement, but ended up building it into the language like I did with if/then/else. Made for a more flexible syntax.