<?xml version="1.0" encoding="UTF-8"?>
<!--
 * Scilab ( https://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="ru" xml:id="select">
    <refnamediv>
        <refname>select</refname>
        <refpurpose>ключевое слово выбора</refpurpose>
    </refnamediv>
    <refsynopsisdiv>
        <title>Syntax</title>
        <synopsis>
            select variable
            case value1 then
                instructions 1
            case value2 then
                instructions 2
                ...
            case valuen then
                instructions n
            case {valueC1 valueC2 valueCN}
                intructions C
           [else
                instructions]
            end
        </synopsis>
    </refsynopsisdiv>
    <refsection>
        <title>Аргументы</title>
        <variablelist>
            <varlistentry>
                <term>variable</term>
                <listitem>
                    <para>
                        переменная, значение которой анализируется.
                    </para>
                </listitem>
            </varlistentry>
            <varlistentry>
                <term>value1, ..., valuen</term>
                <listitem>
                    <para>
                        значения переменной <literal>variable</literal> для которых предусмотрен соответствующий набор
                        инструкций  <literal>instructions 1, ..., instructions n</literal>.
                    </para>
                </listitem>
            </varlistentry>
            <varlistentry>
                <term>valueC1, ..., valueCN</term>
                <listitem>
                    <para>
                        like <literal>value1, ..., valuen</literal> but an OR is applied on each <literal>variable == valueCx</literal>.
                        It is useful to group cases with same instruction.
                    </para>
                </listitem>
            </varlistentry>
            <varlistentry>
                <term>instructions</term>
                <listitem>
                    <para>
                        набор корректных инструкций.
                    </para>
                </listitem>
            </varlistentry>
        </variablelist>
    </refsection>
    <refsection>
        <title>Examples</title>
        <programlisting role="example"><![CDATA[
            function select_example(n)
                select n
                case 0 then
                    disp(0)
                case 1 then
                    disp(1)
                case {2 3}
                    disp({2 3})
                else
                    disp("default")
                end
            endfunction

            select_example(0); // 0
            select_example(1); // 1
            select_example(2); // {2 3}
            select_example(3); // {2 3}
            select_example(4); // "default"

        ]]></programlisting>
    </refsection>
    <refsection role="see also">
        <title>Смотрите также</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>История</title>
        <revhistory>
            <revision>
                <revnumber>6.0.0</revnumber>
                <revdescription>
                    <itemizedlist>
                        <listitem>
                            <literal>select</literal> is now protected:
                            Assignments like <literal>select=1</literal> are no longer possible.
                        </listitem>
                        <listitem>
                            The number of characters used to define the body of any conditional instruction (<literal>if</literal>, <literal>while</literal>, <literal>for</literal>, or <literal>select/case</literal>) is no more limited to 16k.
                        </listitem>
                    </itemizedlist>
                </revdescription>
            </revision>
            <revision>
                <revnumber>2024.0</revnumber>
                <revdescription>
                    <itemizedlist>
                        <listitem>
                            Add grouped case with cell representation <literal>case {2 3}</literal> to match either 2 or 3
                        </listitem>
                    </itemizedlist>
                </revdescription>
            </revision>
        </revhistory>
    </refsection>
</refentry>
