<!-- Converted to DocBook/SGML by Kevin Conder -->
<refentry id="if">
  <refmeta>
    <refentrytitle>if</refentrytitle>
  </refmeta>
 
  <refnamediv>
    <refname>if</refname>

    <refpurpose>
      Branches conditionally at initialization or during performance time.
      <indexterm id="IndexIf"><primary>if</primary></indexterm>
    </refpurpose>
  </refnamediv>
 
  <refsect1>
    <title>Description</title>
    <para>
      <emphasis>if...igoto</emphasis> -- conditional branch at initialization time, depending on the truth value of the logical expression <emphasis>ia</emphasis> <emphasis>R</emphasis> <emphasis>ib</emphasis>. The branch is taken only if the result is true.
    </para>

    <para>
      <emphasis>if...kgoto</emphasis> -- conditional branch during performance time, depending on the truth value of the logical expression <emphasis>ka</emphasis> <emphasis>R</emphasis> <emphasis>kb</emphasis>. The branch is taken only if the result is true.
    </para>

    <para>
      <emphasis>if...goto</emphasis> -- combination of the above. Condition tested on every pass.
    </para>

    <para>
      <emphasis>if...then</emphasis> -- allows the ability to specify conditional <emphasis>if</emphasis>/<emphasis>else</emphasis>/<emphasis>endif</emphasis> blocks.  All <emphasis>if...then</emphasis> blocks must end with an <emphasis>endif</emphasis> statement. <emphasis>elseif</emphasis> and <emphasis>else</emphasis> statements are optional. Any number of <emphasis>elseif</emphasis> statements are allowed. Only one <emphasis>else</emphasis> statement may occur and it must be the last conditional statement before the <emphasis>endif</emphasis> statement. Nested <emphasis>if...then</emphasis> blocks are allowed.
    </para>

    <note>
      <title>Note</title>
      <para>
        Note that if the condition uses a k-rate variable (for instance, <quote>if kval &gt; 0</quote>), the <emphasis>if...goto</emphasis> or <emphasis>if...then</emphasis> statement will be ignored during the i-time pass. This allows for opcode initialization, even if the k-rate variable has already been assigned an appropriate value by an earlier init statement.
      </para>
    </note>
  </refsect1>

  <refsect1>
    <title>Syntax</title>
    <synopsis><command>if</command> ia R ib <command>igoto</command> label</synopsis>

    <synopsis><command>if</command> ka R kb <command>kgoto</command> label</synopsis>

    <synopsis><command>if</command> ia R ib <command>goto</command> label</synopsis>

    <synopsis><command>if</command> xa R xb <command>then</command></synopsis>

    <para>
      where <emphasis>label</emphasis> is in the same instrument block and is not an expression, and where <emphasis>R</emphasis> is one of the Relational operators (<emphasis>&lt;</emphasis>, <emphasis>=</emphasis>, <emphasis>&lt;=</emphasis>, <emphasis>==</emphasis>, <emphasis>!=</emphasis>) (and <emphasis>=</emphasis> for convenience, see also under <link linkend="ControlConditional"><citetitle>Conditional Values</citetitle></link>).
    </para>
  </refsect1>

  <refsect1>
    <title>Examples</title>
    <para>
      Here is an example of the if...igoto combination. It uses the files <ulink url="examples/igoto.orc"><citetitle>igoto.orc</citetitle></ulink> and <ulink url="examples/igoto.sco"><citetitle>igoto.sco</citetitle></ulink>.

      <example>
        <title>Example of the if...igoto combination.</title>

        <programlisting>
<inlinemediaobject>
            <imageobject>
              <imagedata fileref="examples/igoto.orc" format="linespecific">
            </imageobject>
          </inlinemediaobject>
        </programlisting>

        <programlisting>
<inlinemediaobject>
            <imageobject>
              <imagedata fileref="examples/igoto.sco" format="linespecific">
            </imageobject>
          </inlinemediaobject>
        </programlisting>
      </example>

      Its output should include lines like this:
      <screen>
instr 1:  iparam = 0.000
instr 1:  ifreq = 440.000
instr 1:  iparam = 1.000
instr 1:  ifreq = 880.000
      </screen>
    </para>

    <para>
      Here is an example of the if...kgoto combination. It uses the files <ulink url="examples/kgoto.orc"><citetitle>kgoto.orc</citetitle></ulink> and <ulink url="examples/kgoto.sco"><citetitle>kgoto.sco</citetitle></ulink>.

      <example>
        <title>Example of the if...kgoto combination.</title>

        <programlisting>
<inlinemediaobject>
            <imageobject>
              <imagedata fileref="examples/kgoto.orc" format="linespecific">
            </imageobject>
          </inlinemediaobject>
        </programlisting>

        <programlisting>
<inlinemediaobject>
            <imageobject>
              <imagedata fileref="examples/kgoto.sco" format="linespecific">
            </imageobject>
          </inlinemediaobject>
        </programlisting>
      </example>

      Its output should include lines like this:
      <screen>
kval = 0.000000, kfreq = 440.000000
kval = 0.999732, kfreq = 440.000000
kval = 1.999639, kfreq = 880.000000
      </screen>
    </para>
  </refsect1>

  <refsect1>
    <title>Examples</title>
    <para>
      Here is an example of the if...then combo. It uses the files <ulink url="examples/ifthen.orc"><citetitle>ifthen.orc</citetitle></ulink> and <ulink url="examples/ifthen.sco"><citetitle>ifthen.sco</citetitle></ulink>.

      <example>
        <title>Example of the if...then combo.</title>

        <programlisting>
<inlinemediaobject>
            <imageobject>
              <imagedata fileref="examples/ifthen.orc" format="linespecific">
            </imageobject>
          </inlinemediaobject>
        </programlisting>

        <programlisting>
<inlinemediaobject>
            <imageobject>
              <imagedata fileref="examples/ifthen.sco" format="linespecific">
            </imageobject>
          </inlinemediaobject>
        </programlisting>
      </example>
    </para>
  </refsect1>

  <refsect1>
    <title>See Also</title>
    <para>
      <link linkend="elseif"><citetitle>elseif</citetitle></link>,
      <link linkend="else"><citetitle>else</citetitle></link>,
      <link linkend="endif"><citetitle>endif</citetitle></link>,
      <link linkend="goto"><citetitle>goto</citetitle></link>,
      <link linkend="igoto"><citetitle>igoto</citetitle></link>,
      <link linkend="kgoto"><citetitle>kgoto</citetitle></link>,
      <link linkend="tigoto"><citetitle>tigoto</citetitle></link>,
      <link linkend="timout"><citetitle>timout</citetitle></link>
    </para>
  </refsect1>

  <refsect1>
    <title>Credits</title>
    <para>Examples written by &namekevin;.</para>
    <para>Added a note by Jim Aikin.</para>
    <para>February 2004. Added a note by &namematt;.</para>
  </refsect1>
</refentry>
