Conditional Execution IF

IF

Keyword IF is used to conditionally execute a group of statements, depending on the value of a conditional expression. Conditional expression should be used immediately after keyword IF. The group of statements should be terminated by keywords END IF. Example:

if a = 5
	DrawText (10, 10, "A is 5")
end if
For compatibility with other dialects of Basic programming language it is allowed to use keyword THEN after the conditional expression, but it is optional. The code below is equivalent to the example above:
if a = 5 then
	DrawText (10, 10, "A is 5")
end if

ElseIf

A group of statements after keyword ElseIf is executed if its own conditional statement is true, but all previous conditional statements are not true. Example:

if a = 5
	DrawText (10, 10, "A is 5")
elseif a = 6
	DrawText (10, 10, "A is 6")
elseif a < 10
	DrawText (10, 10, "A is less than 10, but not 5 or 6")
end if
You can also use keyword THEN after the conditional statements, but it is also optional. The code below is equivalent to the example above:
if a = 5 then
	DrawText (10, 10, "A is 5")
elseif a = 6 then
	DrawText (10, 10, "A is 6")
elseif a < 10 then
	DrawText (10, 10, "A is less than 10, but not 5 or 6")
end if

ELSE

A group of statements after keyword ELSE is executed when none of the conditional expressions is true:

if a = 5
	DrawText (10, 10, "A is 5")
elseif a = 6
	DrawText (10, 10, "A is 6")
elseif a < 10
	DrawText (10, 10, "A is less than 10, but not 5 or 6")
else
	DrawText (10, 10, "A is greater or equal than 10")
end if

See also: