Enhanced IF Statement
Programming Features - The Enhanced If/Then Statement
The Color 64 ML adds a powerful set of decision-making commands that supplement the IF/THEN statement.
| CMD | Details |
|---|---|
| IF/THEN/ELSE | Format: IF <expression> THEN <statements>: £ <statements>
The British Pound character “£” represents “ELSE” in Color 64 Basic. Example: IF A=5 THEN PRINT "Hello”: £ PRINT "Goodbye" Result: If A were to equal 5, then "Hello" would be printed; otherwise "Goodbye" would be printed instead. |
| AND-ELSE | A variation of the ELSE statement is the AND-ELSE statement. This is represented by the characters '!£'. It behaves the same as the ELSE statement, except that if the expression was TRUE, then the statements after the '!£' are executed ALSO (hence both the first AND the second sections are executed, or ELSE just the second section is executed).
Example: IF A=5 THEN PRINT "Hello”:!£ PRINT "Goodbye" Result: If A were to equal 5 then BOTH "Hello" AND "Goodbye" would be printed, but if the statement were false then only "Goodbye" would be printed. Whatever is after the '!£' is going to be executed regardless of the outcome of the decision. |
| REDECIDE | Format: !+ <expression> or !- <expression>
These commands use the result of the most recent IF/THEN statement to decide if the expression is to be executed. The !+ statement will execute only if the last IF/THEN expression was TRUE. The !- statement will execute only if the last IF/THEN expression was FALSE (hence '+' for TRUE and '-' for FALSE). Example: 10 IF A=5 THEN PRINT "Hello, "; 20 !+PRINT "How Are You?" 30 !- PRINT "What is Your Name?" Result: If A was to equal 5, then both the first and second statements would be executed, which would print "Hello, How Are You?". Conversely, if A was not 5 then only the REDECIDE-FALSE (the !-) statement would be executed, which would print "What is Your Name?" You can also use ELSE with the REDECIDE statements. ELSE will execute if the opposite of the REDECIDE statement 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 was to equal 5, then Joe, Jenna, John and Jack’s names would be printed. Otherwise, Jim, Jessi, Jerry, and Frank’s names would be printed instead. If A was not 5 then "1 2 3 4" would be printed. Note that the execution of a REDECIDE statement, or the alteration of a variable that was in the original IF/THEN statement, does NOT change the true or false nature of the most recent IF/THEN. |
Next Section: ML Command Set