Difference between revisions of "If"

From Mesham
Jump to navigationJump to search
(Created page with '== Syntax == if (condition)<br> {<br> then body<br> } else {<br> else body<br> };<br> == Semantics == Will evaluate the condition and, if true will execute the code in the ''t…')
 
(Example)
Line 14: Line 14:
 
== Example ==
 
== Example ==
  
  if (a==b)
+
#include <io>
{
+
  if (a==b) {
     print["Equal"];
+
     print("Equal");
 
  };
 
  };
  

Revision as of 13:47, 12 January 2013

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