COBOL
. Hello Worldの例
Hello Worldを表示する例:
IDENTIFICATION DIVISION.
PROGRAM-ID. HelloWorld.
PROCEDURE DIVISION.
DISPLAY "Hello, World!".
STOP RUN.
2. 変数の使用例
変数の定義と表示:
IDENTIFICATION DIVISION.
PROGRAM-ID. VariablesExample.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 名前 PIC X(10) VALUE "Alice".
PROCEDURE DIVISION.
DISPLAY "こんにちは、" 名前 "さん!".
STOP RUN.
3. 条件分岐の例
条件分岐:
IDENTIFICATION DIVISION.
PROGRAM-ID. ConditionExample.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 年齢 PIC 99 VALUE 25.
PROCEDURE DIVISION.
IF 年齢 >= 20
DISPLAY "成人です。"
ELSE
DISPLAY "未成年です。"
END-IF.
STOP RUN.
4. ループの例
ループ処理:
IDENTIFICATION DIVISION.
PROGRAM-ID. LoopExample.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 i PIC 99 VALUE 1.
PROCEDURE DIVISION.
PERFORM UNTIL i > 5
DISPLAY "カウント: " i
ADD 1 TO i
END-PERFORM.
STOP RUN.