From 3f23acf49cd368c08cb77213bc263e77d3404c4d Mon Sep 17 00:00:00 2001 From: David Schmenk Date: Wed, 26 Sep 2018 15:51:35 -0700 Subject: [PATCH] Clean up when/is evaluation --- README.md | 24 ++---------------------- 1 file changed, 2 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 6d0917c..99e8d19 100755 --- a/README.md +++ b/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 \ [STEP]/NEXT