Name: if

Type: control structure

Syntax: if <condition> then <statement> [else <elseStatement>]

Summary: <execute|Executes> a list of <statement|statements> if a condition is true.

Introduced: 1.0

OS: mac,windows,linux,ios,android

Platforms: desktop,server,web,mobile

Example:
if tSpeed &lt; 2 then
   answer "That is slow"
else if tSpeed &lt; 5 then
   answer "That is pretty fast"
else if tSpeed &lt; 10 then
   answer "That is a rocket"
else
   answer "You are traveling at the speed of light"
end if

Parameters:
condition (bool): 
statement: 
elseStatement: 
statementList: The statementList or elseStatementList consists of one or more LiveCode statements, and can also include if, switch, try, or repeat control structures. The statement or elseStatement consists of a single LiveCode statement.

Description:
Use the <if> <control structure> to <execute> a <statement> (or list of <statement|statements>) only under certain circumstances.

Form:
The <if> <control structure> always begins with the <word> if. There are four forms of the <if> <control structure>:

if <condition> then <statement> [else <elseStatement>]
(This form may have a line break before the words then or else or both.)

if <condition> then
<statementList> 
[else
elseStatementList]
end if

if <condition> 
then <statement> 
[else
elseStatementList]
end if

if <condition> then
<statementList> 
else <elseStatement> 

If the <condition> <evaluate|evaluates> to true, the <statement> or <statementList> is <execute|executed>; if the <condition> <evaluate|evaluates> to false, the <statement> or <statementList> is skipped.

If the <if> <control structure> contains an <else> clause, the <elseStatement> or elseStatementList is <execute|executed> if the <condition> is false.

If one <if> <control structure> is nested inside another, use of the second form described above is recommended, since the other forms may cause ambiguities in interpreting which <else> clause belongs with which <if> statement.

The <if> <control structure> is most suitable when you want to check a single <condition>. If you need to check for multiple possibilities, doing something different for each one, use a <switch> <control structure> instead.

>*Note:* The <if> <control structure> is implemented internally as a <command> and appears in the <commandNames>.

References: then (keyword), else (keyword), end if (keyword), word (keyword), switch (control_st), statement (glossary), command (glossary), evaluate (glossary), execute (glossary), control structure (glossary), commandNames (function)
