Reading — step 1 of 5
Learn
~1 min readControl Flow
IF/ELSE in COBOL reads like English:
IF AGE >= 18
DISPLAY "adult"
ELSE
DISPLAY "minor"
END-IF.
Note: NO period inside the IF (would terminate the statement). End with END-IF.
EVALUATE is COBOL's switch:
EVALUATE GRADE
WHEN "A"
DISPLAY "excellent"
WHEN "B" THRU "D"
DISPLAY "passing"
WHEN OTHER
DISPLAY "failed"
END-EVALUATE.
Loops via PERFORM:
PERFORM VARYING I FROM 1 BY 1 UNTIL I > 10
DISPLAY I
END-PERFORM.
PERFORM ... TIMES for fixed counts:
PERFORM 5 TIMES
DISPLAY "hi"
END-PERFORM.
PERFORM can also call paragraphs (named code blocks) — COBOL's primitive procedure mechanism.
Discussion
Ask a question, share an insight, or help someone who’s stuck.
Sign in to post a comment or reply.
Loading…