反復子

反復子は、値の順序付けシーケンスを戻すコードのセクションです。反復子は、iterator-id を使用して、メンバを反復子として定義することで作成できます。

iterator-specification

iterator-header procedure-division

iterator-header

access-modifier attribute-clause

ここで、iterator-id 段落 GetEven を使用して、FibonacciArray に偶数を戻します。

    01 m-FibonacciArray binary-long occurs any static.
    01 anyNumber    binary-long.
    procedure division
       ...
       set content of m-FibonacciArray to (1 2 3 5 8 13 21 34 55 89 144)

        display "Even numbers"
        perform varying evenNumbers through iterators::GetEven
            display evenNumbers
        end-perform

    iterator-id GetEven static.
    01 i binary-long.
    procedure division yielding res as binary-long.
        perform varying i through m-FibonacciArray
            if i b-and 1 = 0
                set res to i
                goback
            end-if
        end-perform
        stop iterator *> 反復子をすぐに停止する
    end iterator.     *> 反復子を黙示的に停止する 

反復子のサンプルも参照してください。このサンプルは、[スタート > すべてのプログラム > Micro Focus Enterprise Developer > Samples] の COBOL for JVM の下にあります。

その他の情報

STOP ITERATOR 文は反復を停止します。

この文は、次の文が END ITERATOR の場合は必要ありません。