if, then, elseif, else, endif

条件分岐

1) 書式1

if <int> <statement>

解説

もし <int> が0以外ならば、コマンド <statement> を実行する。

; もし A>1 ならば、':label' へ飛ぶ。
if A>1 goto label

; もし result<>0 ならば、A に0を代入。
if result A=0

2) 書式2

if <int 1> then
  ...
  (<int 1> が真(0以外)の場合に実行されるコマンド)
  ...
[elseif <int 2> then]
  ...
  (<int 1> が偽(0)で、<int 2>が真の場合に実行されるコマンド)
  ...
[elseif <int N> then]
  ...
  (<int 1>, <int 2>,.., <int N-1> がすべて偽で、<int N> が真の場合に実行されるコマンド)
  ...
[else]
  ...
  (上の条件すべてが偽の場合に実行されるコマンド)
  ...
endif

解説

'then' は 'if' と 'elseif' 行の最後になければならない。
'elseif' と 'else' はなくてもよい。
'endif' は必ず必要。

if a=1 then
  b = 1
  c = 2
  d = 3
endif

if i<0 then
  i=0
else
  i=i+1
endif

if i=1 then
  c = '1'
elseif i=2 then
  c = '2'
elseif i=3 then
  c = '3'
else
  c = '?'
endif