Perulangan/Looping adalah Beberapa instruksi diulang untuk suatu jumlah pengulangan yang tertentu. Jumlah pengulangan dapat diketahui sebelumnya atau ditentukan dalam perjalanan program.
Bentuk umum Looping pada COBOL :
GO TO Verb : GO TO . . . DEPENDING VERB, ALTER Verb, PERFORM Verb, Exit Verb
Program Sederhana pertama Looping pada COBOL :
IDENTIFICATION DIVISION.
PROGRAM-ID. MY
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
77 N PIC 9.
PROCEDURE DIVISION.
MULAI.
PERFORM CETAK
VARYING N FROM 1 BY 1 UNTIL N > 5
STOP RUN.
CETAK.
DISPLAY(, ) N.
Program Sederhana kedua Looping pada COBOL :
IDENTIFICATION DIVISION.
PROGRAM-ID. ANDRE.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
77 I PIC 9.
77 J PIC 9.
PROCEDURE DIVISION.
MULAI.
PERFORM CETAK
VARYING I FROM 1 BY 1 UNTIL I > 7
AFTER J FROM 1 BY 1 UNTIL J > I.
STOP RUN.
CETAK.
DISPLAY(, ) I.
IF J = I DISPLAY SPACE.
Program Sederhana ketiga Looping pada COBOL :
IDENTIFICATION DIVISION.
PROGRAM-ID. LOOPING.
AUTHOR. ANDREAS.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
77 PIL PIC 9.
77 L PIC X.
77 I PIC 99.
77 J PIC 99.
77 N PIC 99.
SCREEN SECTION.
01 CLS.
02 BLANK SCREEN.
PROCEDURE DIVISION.
MULAI.
DISPLAY CLS.
DISPLAY '********** MENU **********'.
DISPLAY '| 1. ASTERIX |'.
DISPLAY '| 2. ASTERIX TERBALIK |'.
DISPLAY '| 3. EXIT |'.
DISPLAY '##########################'.
DISPLAY(, ) ' PILIH MENU [1-3] : '.
ACCEPT PIL.
GO TO ASTERIX , AST , SLS DEPENDING ON PIL.
DISPLAY 'MENU TIDAK ADA..'.
ACCEPT L.
GO TO MULAI.
ASTERIX.
DISPLAY(, ) 'MASUKKAN BANYAKNYA PERULANGAN : '.
ACCEPT N.
PERFORM CETAK
VARYING I FROM 1 BY 1 UNTIL I > N
AFTER J FROM 1 BY 1 UNTIL J > I.
STOP RUN.
AST.
DISPLAY(, ) 'MASUKKAN BANYAKNYA PERULANGAN : '.
ACCEPT N.
PERFORM CETAK
VARYING I FROM N BY -1 UNTIL I < 1
AFTER J FROM 1 BY 1 UNTIL J > I.
STOP RUN.
CETAK.
DISPLAY( , ) " * " .
IF J = I DISPLAY SPACE.
SLS.
STOP RUN.
OUTPUT PROGRAM PERTAMA LOOPING PADA COBOL:
OUTPUT PROGRAM KEDUA LOOPING PADA COBOL:
OUTPUT PROGRAM KETIGA LOOPING PADA COBOL:
MOHON UNTUK MENGHARGAI HAK CIPTA SESEORANG
TERIMA KASIH
0 komentar:
Posting Komentar
WRITE YOUR COMMENTS BELOW