Scilab Website | Contribute with GitLab | Mailing list archives | ATOMS toolboxes
Scilab Online Help
6.1.0 - 日本語

Change language to:
English - Français - Português - Русский

Please note that the recommended version of Scilab is 2024.0.0. This page might be outdated.
See the recommended documentation of this function

Scilabヘルプ >> Scilab > Control flow > for

for

ループ用の言語キーワード

説明

ループ定義に使用されます.その構文は以下のようになります: for variable=expression ,instruction, .. ,instruction,end

for variable=expression do instruction, ,instruction,end

expression が行列または行ベクトルの場合, variable の値は行列の各列の値となります.

具体例として,一定間隔の行ベクトルを作成するために コロン演算子を使用し, 典型的な for ループを作成します : for variable=n1:step:n2, ...,end

expression が リストの場合, variableはこのリストの連続するエントリを 値とします.

Scilabプログラミング言語のコード規約に基づき, 以下が推奨されます:

  • 各命令を新しい行で開始する.

  • 1行に複数の命令を記述しない.

  • 複合命令は,複数行に分割する.

例えば, 以下のようにします:

for i = 1:5
    disp(i);
end
以下は推奨されません
for i = 1:5, disp(i); end
警告: 条件文(if while for または select/case)の本体を定義するために 使用できる文字の数は,16k に制限されています.

Common loops:

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

"Decreasing" loop:

for j = 4:-1:1
    j
end

Loop implicitly on the columns of a row vector or of a matrix:

M = [1 2 ; 3 4 ; 5 6]'
for  c = M, c, end
-> 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.
for v = a, write(%io(2),v), end
for j = 1:n, v = a(:,j), write(%io(2),v), end

Loop on entries of a list:

for l = list([1 2;3 4], (1+%z)^3, 'example', [%F %T]); l, end
--> 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

参照

  • while — while キーワード
  • end — end キーワード
  • do — ループ用の言語キーワード

履歴

VersionDescription
6.0.0 The for expression can now be a vector of graphic handles. for is now protected: Assignments like for=1 are no longer possible.
Report an issue
<< end Control flow halt >>

Copyright (c) 2022-2023 (Dassault Systèmes)
Copyright (c) 2017-2022 (ESI Group)
Copyright (c) 2011-2017 (Scilab Enterprises)
Copyright (c) 1989-2012 (INRIA)
Copyright (c) 1989-2007 (ENPC)
with contributors
Last updated:
Tue Feb 25 08:53:17 CET 2020