Contents Previous Next Subchapters Current Chapters-> if block for while break goto halt Parent Chapters-> Omatrix6 flow if Search Tools-> contents reference index search

If Statement
 Syntax `if `logical value` then `first  statement``` if ```logical value` then `first statement` else `second statement See Also equality , ordered , block , goto

Description
Executes the first statement if the logical value is true, where logical value is a scalar. If the second statement is present and the logical value is false, the second statement is executed.

Tutorial
Because O-Matrix cannot process a line containing a partial statement the following examples cannot be typed at the O> prompt. It can be copied from the help file and pasted to the O> prompt or run from an editor window. ``` ```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.

Reference
Directives cannot be used in `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.