if (comparison) { ... }

else { ... }

If the comparison or expression between the round brackets is true or non-zero, all commands between the first pair of winged brackets are executed. Otherwise all commands between the second pair of winged brackets following else will be executed. The else part with the second set of commands can be omitted. The winged brackets can be omitted when only one instruction is to be executed dependent on the comparison.

Example:

if (((x+3)<9) or (y==0))   // set z to 10 if x+3 is below 9, or if y is equal to 0
  z = 10;
else z = 5;// set z to 5 in all other cases

See also:

comparisons, while, switch, ifelse

► latest version online