Skip to content

制御構文

オートプログラムでは、条件分岐(IF)、繰り返し(FOR)、ジャンプ(GOTO)、サブルーチン(GOSUB)が使えます。

IF文(条件分岐)

条件に応じて処理を分岐させます。

if 条件 then:処理:endif:
if 条件 then:処理:else:処理:endif:

if z1=100 then:goto *end:endif:
if c2>1000 then:c2*0.9=c2:endif:
if v1="東京" then:z2=1:else:z2=0:endif:

条件式の演算子

演算子意味
=等しい
<>等しくない
> >=より大きい / 以上
< <=より小さい / 以下

複合条件

if z1>0 and z1<100 then:goto *ok:endif:
if z1=0 or z2=0 then:goto *err:endif:

FOR文(繰り返し)

指定した回数だけ処理を繰り返します。

for 変数=開始値 to 終了値:
  処理
next 変数:

for z1=1 to t1:            全行に対してループ
  c2+c3=c4:
next z1:

STEP(増分の指定)

for z1=1 to 10 step 2:     z1は1, 3, 5, 7, 9
  処理
next z1:

for z1=10 to 1 step -1:    逆順ループ
  処理
next z1:

BREAK / CONTINUE

for z1=1 to 100:
  if [z1,1]="" then:break:endif:        ループを抜ける
  if [z1,2]=0 then:continue:endif:      次の繰り返しへスキップ
  [z1,3]/[z1,2]=[z1,4]:
next z1:

GOTO文(ジャンプ)

指定したラベルに無条件でジャンプします。

goto *ラベル名:

ラベルは *ラベル名 の形式で定義します。

*start
r:1:
if z1>100 then:goto *end:endif:
z1=z1+1:
goto *start:
*end
stop:

GOSUB / RETURN(サブルーチン)

共通処理をサブルーチンとして何度でも呼び出せます。

r:1:
gosub *calc:                サブルーチンを呼び出し
w:1:
r:2:
gosub *calc:                再利用
w:2:
goto *end:

*calc
tl::
av::
return:                     呼び出し元に戻る

*end
stop:

ネスト(入れ子)

FOR文やIF文は入れ子にできます。

for z1=1 to 10:
  for z2=1 to 5:
    if [z1,z2]>100 then:[z1,z2]=[z1,z2]*0.9:endif:
  next z2:
next z1:

次のステップ