IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO-WORLD.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 NAME PIC A(9) VALUE 'FELIX'.
is there other way of looping?
PROCEDURE DIVISION.
PERFORM A-PARA THRU E-PARA.
A-PARA.
DISPLAY 'L'.
B-PARA.
DISPLAY 'I I I'.
C-PARA.
DISPLAY 'A A A A A'.
D-PARA.
DISPLAY 'M M M M M M M'.
This is the Output:
L
III
AAAAA
MMMMMMM
My expecting Output Should be:
L
III
AAAAA
MMMMMMM
thanks for the response in advance. I'm new to this programing language and its very confusing.
CodePudding user response:
Really shouldn't ask people to do your homework . . .
I did this on an openvms machine. You will have to tweak for whatever COBOL environment you are using.
$ cob/reserved_words=200x PYRAMID.COB
$ LINK PYRAMID
$ RUN PYRAMID
*
***
*****
*******
*********
You can get yourself a free account in the same place if you have access to a good VT-100 emulator.
IDENTIFICATION DIVISION.
PROGRAM-ID. A.
*> COB/RESERVED_WORDS=200X PYRAMID.COB
*> LINK PYRAMID
*> RUN PYRAMID
DATA DIVISION.
WORKING-STORAGE SECTION.
01 MY-NUMBERS.
05 START-POS PIC 9(4) USAGE IS COMP VALUE IS ZERO.
05 END-POS PIC 9(4) USAGE IS COMP VALUE IS ZERO.
05 SUB-POS PIC 9(4) USAGE IS COMP.
05 DISTANCE PIC 9(4) USAGE IS COMP.
77 MAX-WIDTH PIC 9(4) USAGE IS COMP VALUE IS 10.
77 CENTER-POS PIC 9(4) USAGE IS COMP VALUE IS 5.
01 MY-DISPLAYS.
05 DISPLAY-LINE.
10 DISPLAY-CELL PIC X OCCURS 10.
PROCEDURE DIVISION.
A000-MAIN.
PERFORM B000-CREATE-PYRAMID
VARYING DISTANCE FROM 0 BY 1
UNTIL DISTANCE IS GREATER THAN 4.
STOP RUN.
B000-CREATE-PYRAMID.
MOVE SPACES TO DISPLAY-LINE.
SUBTRACT DISTANCE FROM CENTER-POS GIVING START-POS.
ADD DISTANCE TO CENTER-POS GIVING END-POS.
PERFORM C000-FILL-LINE
VARYING SUB-POS FROM START-POS BY 1
UNTIL SUB-POS IS GREATER THAN END-POS.
DISPLAY DISPLAY-LINE.
C000-FILL-LINE.
MOVE '*' TO DISPLAY-CELL (SUB-POS).
CodePudding user response:
there are several ways to loop in cobol
go to
how to use GO TO in COBOL (I wouldn't recommend to use)perform
statements https://www.tutorialspoint.com/cobol/cobol_loop_statements.htm