Skip to main content

This is documentation for Caché & Ensemble. See the InterSystems IRIS version of this content.Opens in a new tab

For information on migrating to InterSystems IRISOpens in a new tab, see Why Migrate to InterSystems IRIS?

Do...Loop

条件が True である間、または True になるまで、文のブロックを繰り返します。

Synopsis

Do [{While | Until} condition]
    [statements]
    [Exit Do]
    [statements]
Loop 

Or, you can use this syntax:

Do
    [statements]
    [Exit Do]
    [statements]
Loop [{While | Until} condition]

引数

Do...Loop 文の構文は、以下の部分で構成されています。

condition True または False の数値式または文字列式。
statements 条件がTrue の間、または True になるまで繰り返される、単独もしくは複数の文

概要

Exit Do は、Do...Loop を終了するための補助的な手段であり、Do...Loop 制御構造内でのみ使用します。Exit Do 文は、その数に関係なく、Do...Loop 内の任意の場所に配置することができます。Exit Do は、条件の評価に使用されることが多く (例えば If...Then)、制御を Loop の直後の文に渡します。

入れ子になった Do...Loop 文で使用する場合、Exit Do 文は、入れ子のレベルが 1 つ上のループへ制御を移動します。

以下の例は、Do...Loop 文の使用法を示しています。

Do Until MyNum = 6
  MyNum = Int (6 * Rnd + 1)  ' Generate a random integer between 1 and 6
  Println MyNum
Loop

Dim Check, Counter
Check = True: Counter = 0   ' Initialize variables.
Do                          ' Outer loop.
  Do While Counter < 20     ' Inner loop.
    Counter = Counter + 1   ' Increment Counter.
    If Counter = 10 Then    ' If condition is True...
      Check = False         ' set value of flag to False.
      Exit Do               ' Exit inner loop.
    End If
  Loop
Loop Until Check = False    ' Exit outer loop immediately.

関連項目

FeedbackOpens in a new tab