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

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 > if then else

if then else

条件付き実行

呼び出し手順

if expr1 then
statements
elseif expri then
statements
....
else
statements
end

引数

expr1, expri

論理式

statements

有効な命令のブロック

説明

if 命令は論理式を評価し,その値が真の時に 一連の命令を実行します.

expri は数値または論理値を値とする式です. expri が行列の場合, 全ての行列のエントリが真またはゼロでない場合にのみ その条件は真となります.

オプションの elseif および else により, 別の命令のグループを実行することができます. ifに対応する end キーワードにより,最後の命令のグループが 終了します. 上記の行の構造には意味がなく,唯一の拘束条件は, 各thenキーワードを対応する if または elseifキーワードと 同じ行に置く必要があることのみです.

キーワード then は,キャリッジ・リターンまたはカンマで 置き換えることができます.

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

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

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

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

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

if rand(1,1) > 0.5 then
disp("True");
else
disp("False");
end

以下は推奨されません.

if rand(1,1) > 0.5 then disp("True"); else disp("False"); end
条件文(if while for または select/case)の内部に記述可能な文字数は 16kに制限されています.

i=2
for j = 1:3,
  if i == j then
    a(i,j) = 2;
  elseif abs(i-j) == 1 then
    a(i,j) = -1;
  else a(i,j) = 0;
  end,
end

参照

  • then — 'if'および'select'のキーワード
  • else — if-then-elseおよびselect-case-then-elseのキーワード
  • elseif — if-then-elseのキーワード
  • end — end キーワード
  • while — while キーワード
  • select — select キーワード
  • boolean — Scilab オブジェクト, 論理値(boolean)変数および演算子 & | ~
  • comparison — 比較, 関係演算子
  • |, || — Binary OR between integers. Logical OR over/between booleans and numbers
  • &, && — Binary AND between integers. Logical AND over/between booleans and numbers

履歴

バージョン記述
6.0.0 if is now protected: Assignments like if=1 are no longer possible.
Report an issue
<< halt Control flow pause >>

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:
Thu Feb 14 15:01:59 CET 2019