Enhanced IF Statement

Revision as of 23:14, 27 February 2026 by Admin (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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.

Enhanced IF/THEN Statements
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:

  • If the expression is TRUE, both the THEN section and the !£ section execute.
  • If the expression is FALSE, only the !£ section executes.

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.

  • !+ executes only if the previous IF/THEN evaluated TRUE.
  • !- executes only if the previous IF/THEN evaluated FALSE.

Example:

10 IF A=5 THEN PRINT "Hello, ";
20 !+ PRINT "How Are You?"
30 !- PRINT "What is Your Name?"

Result: If A equals 5:

"Hello, How Are You?" is printed.

If A does not equal 5:

Only "What is Your Name?" is printed.

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:

Joe, Jenna, John, and Jack are printed.

If A does not equal 5:

Jim, Jessi, Jerry, and Frank are printed.

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

Programming Features