Enhanced IF Statement
Programming Features - The Enhanced If/Then Statement
The Color 64 ML introduces enhanced decision-making commands that expand upon the standard BASIC IF/THEN structure.
| CMD | Details |
|---|---|
| IF / THEN / ELSE | Format: IF <expression> THEN <statements> : £ <statements>
The British Pound character “£” functions as ELSE in Color 64 BASIC. Example: IF A=5 THEN PRINT "Hello" : £ PRINT "Goodbye" Result: If A equals 5, "Hello" is printed. Otherwise, "Goodbye" is printed. |
| AND-ELSE | Represented by the characters "!£".
This behaves similarly to ELSE, but with one important difference:
Example: IF A=5 THEN PRINT "Hello" : !£ PRINT "Goodbye" Result: If A equals 5, both "Hello" and "Goodbye" are printed. If A does not equal 5, only "Goodbye" is printed. Whatever follows "!£" will always execute. |
| REDECIDE | Format: !+ <statement> or !- <statement>
These commands reference the result of the most recent IF/THEN evaluation.
Example: 10 IF A=5 THEN PRINT "Hello, "; 20 !+ PRINT "How Are You?" 30 !- PRINT "What is Your Name?" Result: If A equals 5:
If A does not equal 5:
ELSE may also be combined with REDECIDE statements. In this case, the £ portion executes when the opposite condition of the REDECIDE is true. Example: 10 IF A=5 THEN PRINT "Joe" : £ PRINT "Jim" 20 !+ PRINT "Jenna" : £ PRINT "Jessi" 30 !- PRINT "Jerry" : £ PRINT "John" 40 !+ PRINT "Jack" : £ PRINT "Frank" Result: If A equals 5:
If A does not equal 5:
Important: Executing a REDECIDE statement does not change the TRUE or FALSE status of the most recent IF/THEN. Modifying variables used in the original IF/THEN condition also does not retroactively alter its result. |
Multiple IF/THEN/ELSE Statements on One Line
You may place more than one IF/THEN/ELSE statement on a single line (or any combination of the enhanced decision commands described above). However, it is important to understand how the interpreter evaluates FALSE conditions.
If an IF/THEN expression evaluates FALSE, the interpreter searches forward on the same line for the first “£” (ELSE) symbol that follows that expression.
Example:
IF A=1 THEN C=1 : IF B=1 THEN C=2 : £ C=3
Behavior:
If the expression IF A=1 evaluates FALSE, execution jumps to the first “£” symbol encountered after that expression. In this example, that results in:
C=3
If A=1 evaluates TRUE, then execution continues normally and the second IF/THEN expression is evaluated.
Evaluation results:
A=0, B=0 → C=3 A=0, B=1 → C=3 A=1, B=0 → C=3 A=1, B=1 → C=2
When chaining multiple conditional statements on a single line, carefully consider how ELSE resolution will occur. Misplacing a “£” symbol can cause logic to execute differently than intended.
Next Section: ML Command Set