|
Contents | Previous | Next | Subchapters |
| Syntax |
if logical value then first statementlogical value then first statement else second statement
|
| See Also | equality , ordered , block , goto |
If you enter
x = 8
y = 4
if x / y == 2 then print x, "/", y, "=", x / y
O-Matrix will respond
8 / 4 = 2
The statement following an else
clause is executed if logical value is false.
If you run the program
x = 4
y = 5
if x > y then z = 0
else z = 6
print z
O-Matrix will respond
6
More advanced examples that use the if
statement can be found in the Block
section of this chapter.
if
statements unless as part of a block.
(See the Block
section of this chapter for more information.)
For example, if you enter
if 2 > 1 then const x = 1
O-Matrix will respond with an error message.
An else clause is grouped with the first preceding
if clause that does not yet have an else clause
grouped with it.
If, from an editor window, you run the program
if 2 > 1 then if 1 > 2 then z = 1
else z = 2
print z
O-Matrix will respond
2
The z = 2 statement was executed because 1 > 2 is false.