<?xml version="1.0" encoding="UTF-8"?>
<!--
 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
 * Copyright (C) - INRIA
 * Copyright (C) 2018 - Samuel GOUGEON
 *
 * 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="ja" xml:id="for">
    <refnamediv>
        <refname>for</refname>
        <refpurpose>ループ用の言語キーワード </refpurpose>
    </refnamediv>
    <refsection>
        <title>説明</title>
        <para>
            ループ定義に使用されます.その構文は以下のようになります:
            <literal> for variable=expression ,instruction, .. ,instruction,end</literal>
        </para>
        <para>
            <literal> for variable=expression do instruction,   ,instruction,end</literal>
        </para>
        <para>
            <literal>expression</literal> が行列または行ベクトルの場合,
            <literal>variable</literal> の値は行列の各列の値となります.
        </para>
        <para>
            具体例として,一定間隔の行ベクトルを作成するために
            <link linkend="colon">コロン</link>演算子を使用し,
            典型的な for ループを作成します :
            <literal>for variable=n1:step:n2, ...,end</literal>
        </para>
        <para>
            <literal>expression</literal> が リストの場合,
            <literal>variable</literal>はこのリストの連続するエントリを
            値とします.
        </para>
        <para>
            Scilabプログラミング言語のコード規約に基づき, 以下が推奨されます:
        </para>
        <itemizedlist>
            <listitem>
                <para>
                    各命令を新しい行で開始する.
                </para>
            </listitem>
            <listitem>
                <para>
                    1行に複数の命令を記述しない.
                </para>
            </listitem>
            <listitem>
                <para>
                    複合命令は,複数行に分割する.
                </para>
            </listitem>
        </itemizedlist>
        <para>
            例えば, 以下のようにします:
        </para>
        <screen><![CDATA[
for i = 1:5
    disp(i);
end
]]></screen>
        以下は推奨されません
        <screen><![CDATA[
for i = 1:5, disp(i); end
]]></screen>
        <warning>
            警告: 条件文(if while for または select/case)の本体を定義するために
            使用できる文字の数は,16k に制限されています.
        </warning>
    </refsection>
    <refsection>
        <title>例</title>
        <para>Common loops:</para>
        <programlisting role="example"><![CDATA[
n=5;
for i = 1:n
    for j = 1:n
        a(i,j) = 1/(i+j-1);
    end;
end
for j = 2:n-1
    a(j,j) = j;
end;
a
 ]]></programlisting>
        <para>"Decreasing" loop:</para>
        <programlisting role="example"><![CDATA[
for j = 4:-1:1
    j
end
 ]]></programlisting>
        <para>Loop implicitly on the columns of a row vector or of a matrix:</para>
        <programlisting role="example"><![CDATA[
M = [1 2 ; 3 4 ; 5 6]'
for  c = M, c, end
 ]]></programlisting>
    <screen><![CDATA[
-> M = [1 2 ; 3 4 ; 5 6]'
 M  =
   1.   3.   5.
   2.   4.   6.

--> for  c = M, c, end
 c  =
   1.
   2.

 c  =
   3.
   4.

 c  =
   5.
   6.
]]></screen>
        <programlisting role="example"><![CDATA[
for v = a, write(%io(2),v), end
for j = 1:n, v = a(:,j), write(%io(2),v), end
 ]]></programlisting>
        <para>Loop on entries of a list:</para>
        <programlisting role="example"><![CDATA[
for l = list([1 2;3 4], (1+%z)^3, 'example', [%F %T]); l, end
 ]]></programlisting>
    <screen><![CDATA[
--> for l = list([1 2;3 4], (1+%z)^3, 'example', [%F %T]); l, end
 l  =
   1.   2.
   3.   4.

 l  =
            2   3
   1 +3z +3z  +z

 l  =
 example

 l  =
  F T
]]></screen>
    </refsection>
    <refsection role="see also">
        <title>参照</title>
        <simplelist type="inline">
            <member>
                <link linkend="while">while</link>
            </member>
            <member>
                <link linkend="end">end</link>
            </member>
            <member>
                <link linkend="do">do</link>
            </member>
        </simplelist>
    </refsection>
    <refsection role="history">
        <title>履歴</title>
        <revhistory>
            <revision>
                <revnumber>6.0.0</revnumber>
                <revdescription>
                    The for <literal>expression</literal> can now be a vector of graphic handles.
                    <literal>for</literal> is now protected:
                    Assignments like <literal>for=1</literal> are no longer possible.
                </revdescription>
            </revision>
        </revhistory>
    </refsection>
</refentry>
