SPC  Version 0.9.5
 All Files Functions Groups Pages
The if-else statement

The if-else statement evaluates a condition.

If the condition is true, it executes one statement (the consequence). A second statement (the alternative), preceded by the keyword else, is executed if the condition is false. The value of a condition is considered to be false only when it evaluates to zero. If it evaluates to any non-zero value, it is true. The syntax for an if-else statement is shown below.

if (condition) consequence else alternative

The condition of an if-statement must be enclosed in parentheses, as shown in the code sample below. The compound statement in the last example allows two statements to execute as a consequence of the condition being true as well as two which execute when the condition is false.

if (x==1)
y = 3;
y = 4;
if (x==1) {
y = 1;
z = 2;
else {
y = 3;
z = 5;