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?

For 文 (1)

For 文を使用すると、コードのセクションを繰り返し実行できます。以下は For の引数の構文です。変数、開始値、増分値、終了値が割り当てられています。すべての値は正、または負で、コロンで区切られています。For に続くコード・ブロックは、変数に割り当てられた各値を繰り返します。

また、For の引数にリストの値を割り当てることもできます。この場合、コード・ブロックはそれぞれのリスト項目を、変数に繰り返し割り当てます。他の文と同様、For 文はコンマで区切られた複数の引数を持つことができます。また、1 つの For 文にカウンタとリスト引数の両方を持つことができます。

SAMPLES>do ^forexample

I 1 the sandbox.
I 2 the sandbox.
I 3 the sandbox.
I 4 the sandbox.
I 5 the sandbox.
I 6 the sandbox.
I 7 the sandbox.
I 8 the sandbox.

Was John the leader? y
Was Paul the leader? n
Was George the leader? n
Was Ringo the leader? n

forexample.mac コードのパート 1 は以下のとおりです。

forexample ; examples of the for construct
    for i = 1:1:8 {
        write !, "I ", i, " the sandbox."
    }
    write !!
    for b = "John", "Paul", "George", "Ringo" {
        write !, "Was ", b, " the leader? "
        read yn
    }
FeedbackOpens in a new tab