<?xml version="1.0" encoding="UTF-8"?>
<!--
 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
 * Copyright (C) 2008 - INRIA
 *
 * Copyright (C) 2012 - 2016 - Scilab Enterprises
 *
 * This file is hereby licensed under the terms of the GNU GPL v2.0,
 * pursuant to article 5.3.4 of the CeCILL v.2.1.
 * This file was originally licensed under the terms of the CeCILL v2.1,
 * and continues to be available under such terms.
 * For more information, see the COPYING file which you should have received
 * along with this program.
 *
 -->
<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" xmlns:scilab="http://www.scilab.org" xml:lang="en" xml:id="select">
    <refnamediv>
        <refname>select</refname>
        <refpurpose>select keyword</refpurpose>
    </refnamediv>
    <refsynopsisdiv>
        <title>Syntax</title>
        <synopsis>
            select variable
            case value1 then
            instructions 1
            case value2 then
            instructions 2
            ...
            case valuen then
            instructions n
            [else instructions]
            end
        </synopsis>
    </refsynopsisdiv>
    <refsection>
        <title>Arguments</title>
        <variablelist>
            <varlistentry>
                <term>variable</term>
                <listitem>
                    <para>
                        variable which value to be analyzed.
                    </para>
                </listitem>
            </varlistentry>
            <varlistentry>
                <term>value1, ..., valuen</term>
                <listitem>
                    <para>
                        values of <literal>variable</literal> for which there are appropriate instruction blocks  <literal>instructions 1, ..., instructions n</literal>.
                    </para>
                </listitem>
            </varlistentry>
            <varlistentry>
                <term>instructions</term>
                <listitem>
                    <para>
                        block of valid instructions.
                    </para>
                </listitem>
            </varlistentry>
        </variablelist>
    </refsection>
    <refsection>
        <title>Description</title>
        <para>
            Notes:
        </para>
        <itemizedlist>
            <listitem>
                <para>
                    The only constraint is that each <literal>then</literal>  keyword  must be on
                    the same line as corresponding <literal>case</literal> keyword (or use a
                    continuation mark, see <link linkend="dot">dot</link>).
                </para>
            </listitem>
            <listitem>
                <para>
                    The keyword <literal>"then"</literal>  can be replaced by a carriage return or a comma.
                    <literal>instructions1</literal> are executed if <literal>expr1=expr</literal>, etc.
                </para>
            </listitem>
        </itemizedlist>
        <para>
            According to the Code Conventions for the Scilab Programming Language it is recommended:
        </para>
        <itemizedlist>
            <listitem>
                <para>
                    Start each statement on a new line.
                </para>
            </listitem>
            <listitem>
                <para>
                    Write no more than one simple statement per line.
                </para>
            </listitem>
            <listitem>
                <para>
                    Break compound statements over multiple lines.
                </para>
            </listitem>
        </itemizedlist>
        <para>
            For example, use:
        </para>
        <programlisting role=""><![CDATA[
A = 2
select A
case 1 then
    disp(1)
case 2 then
    disp(2)
else
    disp(3)
end
]]></programlisting>
        <para>
            rather than
        </para>
        <programlisting role=""><![CDATA[
A = 2;select A case 1 then disp(1); case 2 then disp(2); else  disp(3); end
]]></programlisting>
        <para>
            <warning>
                Warning: the number of characters used to define the body of any
                conditional instruction (if while for or select/case) must be limited to
                16k.
            </warning>
        </para>
    </refsection>
    <refsection>
        <title>Examples</title>
        <programlisting role="example"><![CDATA[
while %t do
    n=round(10*rand(1,1))
    select n
        case 0 then
        disp(0)
    case 1 then
        disp(1)
    else
        break
    end
end
 ]]></programlisting>
    </refsection>
    <refsection role="see also">
        <title>See also</title>
        <simplelist type="inline">
            <member>
                <link linkend="if">if</link>
            </member>
            <member>
                <link linkend="while">while</link>
            </member>
            <member>
                <link linkend="for">for</link>
            </member>
        </simplelist>
    </refsection>
    <refsection role="history">
        <title>History</title>
        <revhistory>
            <revision>
                <revnumber>6.0.0</revnumber>
                <revdescription>
                  <literal>select</literal> is now protected:
                  Assignments like <literal>select=1</literal> are no longer possible.
                </revdescription>
            </revision>
        </revhistory>
    </refsection>
</refentry>
