0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Gnu-COBOL PERFORMでループ

Last updated at Posted at 2020-09-03

TIMES

PERFORM ... TIMES ... END-PERFORM.

IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO.

DATA DIVISION.
  WORKING-STORAGE SECTION.
    01 COUNTER PIC 9(3) VALUE 1.
PROCEDURE DIVISION.
  MAIN SECTION.
    PERFORM 10 TIMES
      DISPLAY "COUNTER = " COUNTER
      ADD 1 TO COUNTER
    END-PERFORM.
  STOP RUN.

UNTIL

PERFORM ... UNTIL ... END-PERFORM.

IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO.

DATA DIVISION.
  WORKING-STORAGE SECTION.
    01 COUNTER PIC 9(3) VALUE 1.
PROCEDURE DIVISION.
  MAIN SECTION.
    PERFORM UNTIL COUNTER > 10
      DISPLAY "COUNTER = " COUNTER
      ADD 1 TO COUNTER
    END-PERFORM.
  STOP RUN.

VARYING

PERFORM VARYING ... UNTIL ... END-PERFORM.

IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO.

DATA DIVISION.
  WORKING-STORAGE SECTION.
    01 COUNTER PIC 9(3) VALUE 1.
PROCEDURE DIVISION.
  MAIN SECTION.
    PERFORM VARYING COUNTER FROM 1 BY 1 UNTIL COUNTER > 10 *> 「FROM A BY B UTILE」 -> AからBづつ
      DISPLAY "COUNTER = " COUNTER
    END-PERFORM.
  STOP RUN.

コンパイル

USER-no-MacBook-Air:COBOL user$ cobc -x --free hello.cob

実行

USER-no-MacBook-Air:COBOL user$ ./hello
COUNTER = 001
COUNTER = 002
COUNTER = 003
COUNTER = 004
COUNTER = 005
COUNTER = 006
COUNTER = 007
COUNTER = 008
COUNTER = 009
COUNTER = 010
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?