mirror of
https://github.com/dschmenk/PLASMA.git
synced 2025-02-02 16:34:26 +00:00
Clean up when/is evaluation
This commit is contained in:
parent
2d8f2b9b22
commit
3f23acf49c
24
README.md
24
README.md
@ -518,7 +518,7 @@ else
|
||||
fin
|
||||
```
|
||||
|
||||
The `when`/`is`/`otherwise`/`wend` statement is similar to the `if`/`elsif`/`else`/`fin` construct except that it is more efficient. It selects one path based on the evaluated expressions, then merges the code path back together at the end. Only the `when` value is compared against a list of expressions. The expressions do not need to be constants, they can be any valid expression. The list of expressions is evaluated in order, so for efficiency sake, place the most common cases earlier in the list. Just as in C programs, a `break` statement is required to keep one clause from falling through to the next. Falling through from one clause to the next can have its uses, so this behavior has been added to PLASMA.
|
||||
The `when`/`is`/`otherwise`/`wend` statement is similar to the `if`/`elsif`/`else`/`fin` construct except that it is more efficient. It selects one path based on the evaluated expressions, then merges the code path back together at the end. Only the `when` value is compared against a list of constant. Just as in C programs, a `break` statement is required to keep one clause from falling through to the next. Falling through from one clause to the next can have its uses, so this behavior has been added to PLASMA.
|
||||
|
||||
```
|
||||
when keypressed
|
||||
@ -1139,7 +1139,7 @@ The common `if` test can have optional `elsif` and/or `else` clauses. Any expres
|
||||
|
||||
#### WHEN/IS/[OTHERWISE]/WEND
|
||||
|
||||
The complex test case is handled with `when`. Basically an `if`, `elsif`, `else` list of comparisons, it is generally more efficient. The `is` value can be any expression. It is evaluated and tested for equality to the `when` value.
|
||||
The complex test case is handled with `when`. Basically an `if`, `elsif`, `else` list of comparisons, it is generally more efficient. The `is` value must be a constant.
|
||||
|
||||
```
|
||||
when key
|
||||
@ -1162,26 +1162,6 @@ when key
|
||||
wend
|
||||
```
|
||||
|
||||
With a little "Yoda-Speak", some fairly complex test can be made:
|
||||
|
||||
```
|
||||
const FALSE = 0
|
||||
const TRUE = NOT FALSE
|
||||
|
||||
byte a
|
||||
|
||||
when TRUE
|
||||
is (a <= 10)
|
||||
// 10 or less
|
||||
break
|
||||
is (a > 10) AND (a < 20)
|
||||
// between 10 and 20
|
||||
break
|
||||
is (a >= 20)
|
||||
// 20 or greater
|
||||
wend
|
||||
```
|
||||
|
||||
A `when` clause can fall-through to the following clause, just like C `switch` statements by leaving out the `break`.
|
||||
|
||||
#### FOR \<TO,DOWNTO\> [STEP]/NEXT
|
||||
|
Loading…
x
Reference in New Issue
Block a user