Propeller Manual

Table Of Contents
2: Spin Language Reference – CASE
Propeller Manual v1.1 · Page 61
expression that is a match has its block of code executed; no further expressions are tested
after that. This means that if we had rearranged the 25 and 20..30 lines, so that the range of
20..30 is checked first, we’d have a bug in our code. We did this below:
case X+Y 'Test X+Y
10, 15: !outa[0] 'X+Y = 10 or 15? Toggle P0
20..30: !outa[2] 'X+Y in 20 to 30? Toggle P2
25 : !outa[1] 'X+Y = 25? Toggle P1 <-- THIS NEVER RUNS
The above example contains an error because, while X + Y could be equal to 25, that match
expression would never be tested since the previous one, 20..30 would be tested first, and
since it is true, its block is executed and no further match expressions are checked.
Variations of Statement(s)
The above examples only use one line per Statement(s) block, but each block can be many
lines of course. Additionally, the Statement(s) block may also appear below, and slightly
indented from, the MatchExpression itself. The following two examples show these
variations.
case A 'Test A
4 : !outa[0] 'A = 4? Toggle P0
Z+1 : !outa[1] 'A = Z+1? Toggle P1
!outa[2] 'And toggle P2
10..15: !outa[3] 'A in 10 to 15? Toggle P3
case A 'Test A
4: 'A = 4?
!outa[0] 'Toggle P0
Z+1: 'A = Z+1?
!outa[1] 'Toggle P1
!outa[2] 'And toggle P2
10..15: 'A in 10 to 15?
!outa[3] 'Toggle P3