<topic template="Default" lasteditedby="Georg Kiehne" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../helpproject.xsd" status="Needs Review">
  <title translate="true">Conditions and Loops</title>
  <body>
    <header>
      <para styleclass="Heading1"><text styleclass="Heading1" translate="true">Conditions and Loops</text></para>
    </header>
    <para styleclass="Normal"><table styleclass="Default" rowcount="1" colcount="1" style="width:654px;">
      <tr style="vertical-align:top">
        <td style="width:642px;">
          <para styleclass="Normal"><text styleclass="Normal" translate="true">Apophysis script supports conditional execution of code through branching statements:</text></para>
          <para styleclass="Normal"></para>
          <para styleclass="Normal" style="text-indent:0px; margin-right:0px; margin-left:9px;"><text styleclass="Code Example" translate="true">if J &lt;&gt; 0 then Result := I/J; </text><br/><text styleclass="Code Example" translate="true">if J = 0 then Exit else Result := I/J; </text><br/><text styleclass="Code Example" translate="true">if J &lt;&gt; 0 then </text><br/><text styleclass="Code Example" translate="true">begin </text><br/><text styleclass="Code Example" translate="true">  Result := I/J; </text><br/><text styleclass="Code Example" translate="true">  Count := Count + 1; </text><br/><text styleclass="Code Example" translate="true">end else begin</text><br/><text styleclass="Code Example" translate="true">  Done := True; </text><br/><text styleclass="Code Example" translate="true">end;</text></para>
          <para styleclass="Normal" style="text-indent:0px; margin-right:0px; margin-left:9px;"></para>
          <para style="margin-top:7px; margin-bottom:7px; margin-left:10px;"><text styleclass="Code Example" translate="true">case fruit of </text><br/><text styleclass="Code Example" translate="true">  &apos;lime&apos;: ShowMessage(&apos;green&apos;); </text><br/><text styleclass="Code Example" translate="true">  &apos;orange&apos;: ShowMessage(&apos;orange&apos;); </text><br/><text styleclass="Code Example" translate="true">  &apos;apple&apos;: ShowMessage(&apos;red&apos;); </text><br/><text styleclass="Code Example" translate="true">else </text><br/><text styleclass="Code Example" translate="true">  ShowMessage(&apos;black&apos;); </text><br/><text styleclass="Code Example" translate="true">end; </text><br/></para>
          <para styleclass="Normal"><text styleclass="Normal" translate="true">Please note that a semicolon (&quot;;&quot;) is not allowed directly before the &quot;else&quot;-keyword.</text></para>
          <para styleclass="Normal"></para>
          <para styleclass="Normal"><text styleclass="Normal" translate="true">Additionally, you can define loops through the following statements:</text></para>
          <para styleclass="Normal"></para>
          <para styleclass="Code Example" style="text-indent:0px; margin-right:0px; margin-left:8px;"><text styleclass="Code Example" translate="true">while Data[I] &lt;&gt; X do I := I + 1; </text><br/><text styleclass="Code Example" translate="true">while I &gt; 0 do </text><br/><text styleclass="Code Example" translate="true">begin </text><br/><text styleclass="Code Example" translate="true">  I := I div 2; </text><br/><text styleclass="Code Example" translate="true">  X := Sqr(X); </text><br/><text styleclass="Code Example" translate="true">end; </text></para>
          <para styleclass="Code Example" style="text-indent:0px; margin-right:0px; margin-left:8px;"></para>
          <para style="text-indent:-1px; margin-top:7px; margin-bottom:7px; margin-left:8px;"><text styleclass="Code Example" translate="true">repeat </text><br/><text styleclass="Code Example" translate="true">  K := I mod J; </text><br/><text styleclass="Code Example" translate="true">  I := J; </text><br/><text styleclass="Code Example" translate="true">  J := K; </text><br/><text styleclass="Code Example" translate="true">until J = 0; </text><br/><br/><text styleclass="Code Example" translate="true">continue_loop := true;</text><br/><text styleclass="Code Example" translate="true">repeat </text><br/><text styleclass="Code Example" translate="true">  continue_loop := InputQuery(&apos;My Script&apos;, &apos;Enter a value (0..9): &apos;, I); </text><br/><text styleclass="Code Example" translate="true">until ((I &gt;= 0) and (I &lt;= 9)) or (not continue_loop); </text><br/><br/><text styleclass="Code Example" translate="true">for i:=a to b do </text><br/><text styleclass="Code Example" translate="true">begin </text><br/><text styleclass="Code Example" translate="true">  j:=i^2; </text><br/><text styleclass="Code Example" translate="true">  sum:=sum+j; </text><br/><text styleclass="Code Example" translate="true">end; </text><br/></para>
        </td>
      </tr>
    </table></para>
    <para styleclass="Normal"></para>
    <para styleclass="Image Caption"><text styleclass="Image Caption" translate="true">Jump to: </text><link displaytype="text" defaultstyle="true" type="topiclink" href="Identifiers" styleclass="Image Caption" translate="true">Identifiers</link><text styleclass="Image Caption" translate="true"> - </text><link displaytype="text" defaultstyle="true" type="topiclink" href="Literals_and_operators" styleclass="Image Caption" translate="true">Literals and Operators</link><text styleclass="Image Caption" translate="true"> - </text><link displaytype="text" defaultstyle="true" type="topiclink" href="Conditions_and_Loops" styleclass="Image Caption" translate="true">Conditions and Loops</link><text styleclass="Image Caption" translate="true"> - </text><link displaytype="text" defaultstyle="true" type="topiclink" href="Procedures_and_functions" styleclass="Image Caption" translate="true">Procedures and Functions</link><text styleclass="Image Caption" translate="true"> - </text><link displaytype="text" defaultstyle="true" type="topiclink" href="Comments" styleclass="Image Caption" translate="true">Comments</link></para>
  </body>
</topic>
