このセクションでは、Curl® 言語の分岐式について説明します。分岐式を使用してループ式のフロー制御を強化できます。Curl 言語には、次の分岐式が含まれています。
要約: | - continue 式は、現在のループの繰り返しの最後、または、next 内に制御を移します。
- Curl® RTE は続いてループ条件を再評価します。
|
ループ内から
continue 式を使用してプログラム制御を移すことができます。現在のループの最後にプログラム制御を移したり、ループが他のループ内にネストされる場合は外側のループにプログラム制御を移すことができます。
continue 式の実行後、ループ条件が常に再評価されます。つまり、
continue 式により、現在のループの繰り返しの最後に制御が移動することになります。(ループには、
while、
until および
for 式が含まれます。)
tag 句なしで continue 式を指定すると、現在のループの最後に制御が移動します。さらに、次に実行するコードを決定する前にループ条件が再評価されます。tag 句を指定すると、指定したタグ名を持つループの最後に制御を移動します。
next キーワードがループ内に存在する場合は、
continue 式は、
next キーワードで既定されているコードに制御を移します。
continue 式の構文を次に示します。
構文: | {continue [tag=tag-name]} |
|
tag-name | タブ付きの囲みループ名です。タグ名は有効な Curl 言語の識別子を使用します。タグ句の使用はオプションです。 |
|
次の例では、タグを指定せずに continue 式を使用しています。
例:
continue 式の使用 |
|
{value
|| Define and initialize an integer variable i.
|| Define a vertical box variable "message" to store
|| and display a string.
let i:int=0
let message:VBox={VBox}
|| while i is less than 2, do the following:
|| - Increment i (add 1 to its value).
|| - Place an appropriate string in message.
|| - Perform the for loop.
|| - Place an appropriate string in message.
{while i < 2 do
set i = i + 1
{message.add "outer loop: start iteration for i = " & i}
|| For values of j between 0 and 5, do the
|| following:
|| - If j is 3, "continue" the "for" loop.
|| - Place an appropriate string in message.
{for j = 0 to 5 do
{if j == 3 then
{continue}
}
||-- next
{message.add "inner loop: j = " & j}
}
{message.add "outer loop: end of iteration"}
}
|| Display the contents of message.
message
}
| |
上例では、j が 3 と等しい場合は for ループの最後に制御が移動し、次に for ループ条件をテストします。この for ループ条件が満たされていないので、次の for ループの繰り返しが開始されます。
next キーワードを含む行からコメントを除くと、
continue 式のターゲットとして扱われます。
上例では、
j が
3 と一致する場合に次のコードは実行されます。
{message.add "inner loop: j = " & j}
inner loop: j = 3 がアウトプットに追加されます。
次の例では、タグ名を指定して continue 式を使用しています。
例:
タグ名を指定して continue 式を使用 |
|
{value
|| Define and initialize an integer variable i.
|| Define a vertical box variable "message" to store
|| and display a string.
let i:int=0
let message:VBox={VBox}
|| while i is less than 2, do the following:
|| - Increment i (add 1 to its value).
|| - Place an appropriate string in message.
|| - Perform a for loop.
|| - Place an appropriate string in message.
{while tag=outer-loop, i < 2 do
set i = i + 1
{message.add "outer loop: start iteration for i = " & i}
|| For values of j between 0 and 5, do the
|| following:
|| - If j is 3, "continue" the "for" loop.
|| - Place an appropriate string in message.
{for j = 0 to 5 do
{if j == 3 then
{continue tag=outer-loop}
}
{message.add "inner loop: j = " & j}
}
||-- next
{message.add "outer loop: end of iteration"}
}
|| Display the contents of message.
message
}
| |
上例のように、j が 3 と等しい場合は outer-loop タグ (while ループ) を指定してループの最後に制御が移動します。while ループ条件をテストして実行を続けます。
上の状態では、次のコードは実行されません。
{message.add "outer loop: end of iteration"}
next キーワードを含む行からコメントを除くと、
next は、
continue 式のターゲットとして扱われます。
結果として、
next の次の行のコードが実行され、
outer loop: end of iteration がアウトプットに追加されます。
break 式を使用してループを終了することができます。現在のループ外にプログラム制御を移したり、ループが他のループ内にネストされる場合は外側のループにプログラム制御を移すことができます。つまり、通常ではループがコードを繰り返し実行するような場合でも、
break 式によりループを終了できます。(ループには、
while、
until および
for 式が含まれます。)
tag 句なしで break 式を指定すると、現在のループを終了します。tag 句を指定すると、指定したタグ名でループを終了します。
break 式の構文を次に示します。
構文: | {break [tag=tag-name]} |
|
tag-name | タグ付きの囲みループ名です。タグ名は有効な Curl 言語の識別子を使用します。タグ句の使用はオプションです。 |
|
次の例では、タグを指定せずに break 式を使用しています。
例:
break 式の使用 |
|
{value
|| Define and initialize an integer variable i.
|| Define a vertical box variable "message" to store
|| and display a string.
let i:int=0
let message:VBox={VBox}
|| While i is less than 2, do the following:
|| - Increment i (add 1 to its value).
|| - Place an appropriate string in message.
|| - Perform a for loop.
|| - Place an appropriate string in message.
{while i < 2 do
set i = i + 1
{message.add "outer loop: start iteration for i = " & i}
|| For values of j between 0 and 5, do the
|| following:
|| - If j is 3, "break" the "for" loop.
|| - Place an appropriate string in message.
{for j = 0 to 4 do
{if j == 3 then
{break}
}
{message.add "inner loop: j = " & j}
}
{message.add "outer loop: end of iteration"}
}
|| Display the contents of message.
message
}
| |
上例のように、j が 3 と等しい場合は for ループを終了し、for ループに続く最初の式に制御を移します。
複数の囲みループに一致するタグ名を持つ break 式に遭遇すると、最も内側の囲みループを出ます。
Copyright © 1998-2019 SCSK Corporation.
All rights reserved.
Curl, the Curl logo, Surge, and the Surge logo are trademarks of SCSK Corporation.
that are registered in the United States. Surge
Lab, the Surge Lab logo, and the Surge Lab Visual Layout Editor (VLE)
logo are trademarks of SCSK Corporation.