if (comparison) { instructions... }

else { instructions... }

If the comparison between the round brackets is true (i.e. evaluates to non-zero), all instructions between the first pair of winged brackets are executed. It it's not true (i.e. evaluates to zero), the instructions between the second pair of winged brackets following else will be executed. The else part with the second set of instructions can be omitted. The winged brackets can be omitted when only one instruction is to be executed dependent on the comparison.




if (((x+3)<9) || (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

► latest version online