<doc>
  <legacy_id>2302</legacy_id>
  <name>if</name>
  <type>control structure</type>
  <syntax>
    <example>if <i>condition</i> then <i>statement</i> [else <i>elseStatement</i>]</example>
  </syntax>
  <library></library>
  <objects>
  </objects>
  <synonyms>
  </synonyms>
  <classification>
    <category>Writing LiveCode</category>
  </classification>
  <references>
    <control_st tag="switch">switch Control Structure</control_st>
    <keyword tag="else">else Keyword</keyword>
    <keyword tag="then">then Keyword</keyword>
    <keyword tag="end if">end if Keyword</keyword>
  </references>
  <history>
    <introduced version="1.0">Added.</introduced>
  </history>
  <platforms>
    <mac/>
    <windows/>
    <linux/>
    <ios/>
    <android/>
  </platforms>
  <classes>
    <desktop/>
    <server/>
    <web/>
    <mobile/>
  </classes>
  <security>
  </security>
  <summary><glossary tag="execute">Executes</glossary> a list of <glossary tag="statement">statements</glossary> if a condition is true.</summary>
  <examples>
  <example><p>if tSpeed &lt; 2 then</p><p>   answer "That is slow"</p><p>else if tSpeed &lt; 5 then</p><p>   answer "That is pretty fast"</p><p>else if tSpeed &lt; 10 then</p><p>   answer "That is a rocket"</p><p>else</p><p>   answer "You are traveling at the speed of light"</p><p>end if</p></example>   
  </examples>
  <description>
    <p>Use the <b>if</b> <glossary tag="control structure">control structure</glossary> to <glossary tag="execute">execute</glossary> a <glossary tag="statement">statement</glossary> (or list of <glossary tag="statement">statements</glossary>) only under certain circumstances.</p><p/><p><b>Form:</b></p><p>The <b>if</b> <glossary tag="control structure">control structure</glossary> always begins with the <keyword tag="word">word</keyword> <code>if</code>. There are four forms of the <b>if</b> <glossary tag="control structure">control structure</glossary>:</p><p/><p><code>if <i>condition</i> then <i>statement</i> [else <i>elseStatement</i>]</code></p><p>(This form may have a line break before the words<code> then </code>or<code> else</code> or both.)</p><p/><p><code>if <i>condition</i> then</code></p><p><code><i>statementList</i></code></p><p><code>[else</code></p><p><code><i>elseStatementList</i>]</code></p><p><code>end if</code></p><p/><p><code>if <i>condition</i></code></p><p><code>then <i>statement</i></code></p><p><code>[else</code></p><p><code><i>elseStatementList</i>]</code></p><p><code>end if</code></p><p/><p><code>if <i>condition</i> then</code></p><p><code><i>statementList</i></code></p><p><code>else <i>elseStatement</i></code></p><p/><p><b>Parameters:</b></p><p>The <i>condition</i> is any <glossary tag="expression">expression</glossary> that <glossary tag="evaluate">evaluates</glossary> to true or false.</p><p/><p>The <i>statementList</i> or <i>elseStatementList</i> consists of one or more <glossary tag="LiveCode">LiveCode</glossary> <glossary tag="statement">statements</glossary>, and can also include <control_st tag="if">if</control_st>, <control_st tag="switch">switch</control_st>, <control_st tag="try">try</control_st>, or <control_st tag="repeat">repeat</control_st> <glossary tag="control structure">control structures</glossary>. The <i>statement</i> or <i>elseStatement</i> consists of a single <glossary tag="LiveCode">LiveCode</glossary> <glossary tag="statement">statement</glossary>.</p><p/><p><b>Comments:</b></p><p>If the <i>condition</i> <glossary tag="evaluate">evaluates</glossary> to true, the <i>statement</i> or <i>statementList</i> is <glossary tag="execute">executed</glossary>; if the <i>condition</i> <glossary tag="evaluate">evaluates</glossary> to false, the <i>statement</i> or <i>statementList</i> is skipped.</p><p/><p>If the <b>if</b> <glossary tag="control structure">control structure</glossary> contains an <keyword tag="else">else</keyword> clause, the <i>elseStatement</i> or <i>elseStatementList</i> is <glossary tag="execute">executed</glossary> if the <i>condition</i> is false.</p><p/><p>If one <b>if</b> <glossary tag="control structure">control structure</glossary> is nested inside another, use of the second form described above is recommended, since the other forms may cause ambiguities in interpreting which <keyword tag="else">else</keyword> clause belongs with which <b>if</b> statement.</p><p/><p>The <b>if</b> <glossary tag="control structure">control structure</glossary> is most suitable when you want to check a single <i>condition</i>. If you need to check for multiple possibilities, doing something different for each one, use a <control_st tag="switch">switch</control_st> <glossary tag="control structure">control structure</glossary> instead.</p><p/><p><code/><b>Note:</b><code/> The <b>if</b> <glossary tag="control structure">control structure</glossary> is implemented internally as a <glossary tag="command">command</glossary> and appears in the <function tag="commandNames">commandNames</function>.</p>
  </description>
</doc>