The If Construct

The If construct is a simple statement which decides whether or not a piece of code should be executed.

In it's most basic form it looks like this...

if condition
...
end if

The code contained inside the if statement is executed only if the condition is true.

Else

If statements can also have an else case attached. e.g.

if condition
...
else
...
end if

The first piece of code contained inside the if statement is executed only if the condition is true. The code after the else statement is executed if the condition is false. The else statement must be the last choice before the end if command.

Else If

If statements can also have else ifs attached. e.g.

if condition 1
...
'Section A
else if condition 2
...
'Section B
else if condition 3
...
'Section C
else
...
'Section D
end if

Section A only is executed if condition 1 is true.
Section B only is executed if condition 2 is true.
Section C only is executed if condition 3 is true.
If none of the above conditions are true then section D (the code contained inside the else section) is executed.


Table of contents