If

From Mesham
Revision as of 13:47, 12 January 2013 by Polas (talk | contribs) (Example)
Jump to navigationJump to search

Syntax

if (condition)
{
then body
} else {
else body
};

Semantics

Will evaluate the condition and, if true will execute the code in the then body. Optionally, if the condition is false then the code in the else body will be executed if this has been supplied by the programmer.

Example

#include <io>
if (a==b) {
   print("Equal");
};

In this code example two variables a and b are tested for equality. If equal then the message will be displayed. As no else section has been specified then no specific behaviour will be adopted if they are unequal