Enhanced if statement: Difference between revisions
No edit summary |
No edit summary |
||
| (3 intermediate revisions by the same user not shown) | |||
| Line 33: | Line 33: | ||
Result: | Result: | ||
If A equals 5, both "Hello" and "Goodbye" are printed. | If A equals 5, both "Hello" and "Goodbye" are printed. | ||
If A does not equal 5, only "Goodbye" is printed. | If A does not equal 5, only | ||
"Goodbye" is printed. | |||
Whatever follows "!£" will always execute. | Whatever follows "!£" will always execute. | ||
| Line 74: | Line 75: | ||
Important: | 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. | 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. | ||
|- | |||
| ENDIF | |||
| Use Commodore LEFT ARROW (←) for an ENDIF/REJOIN | |||
Use with IF and ELSE statements to continue execution within a statement. In more modern basic terms, this would be similar to: | |||
IF D(10)<0 THEN | |||
D(10)=ABS(D(10)) | |||
II$="1" | |||
ELSE | |||
II$="0" | |||
END IF | |||
<following execution code> | |||
|} | |} | ||
| Line 103: | Line 117: | ||
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. | 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: [[ | Next Section: [[use of go command|Use of GO() Command]] | ||
[[programming features|Programming Features]] | [[programming features|Programming Features]] | ||
Latest revision as of 21:48, 3 August 2026
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. |
| ENDIF | Use Commodore LEFT ARROW (←) for an ENDIF/REJOIN
Use with IF and ELSE statements to continue execution within a statement. In more modern basic terms, this would be similar to: IF D(10)<0 THEN D(10)=ABS(D(10)) II$="1" ELSE II$="0" END IF <following execution code> |
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: Use of GO() Command