COBOL interview question on PERFORM VARYING.

All sort of Mainframes Interview Questions.
Post Reply
utkarsh
Registered Member
Posts: 66
Joined: Fri Jun 21, 2013 10:32 pm
India

COBOL interview question on PERFORM VARYING.

Post by utkarsh »

Hi,

Please guide on this interview question, What is the content of RESULT after execution of the following COBOL instruction. The start value of RESULT is 0.

Code: Select all

PERFORM VARYING C FROM 1 BY 1 UNTIL C = 6
ADD 1 TO RESULT
END-PERFORM
User avatar
Robert Sample
Global Moderator
Global Moderator
Posts: 1896
Joined: Fri Jun 28, 2013 1:22 am
Location: Dubuque Iowa
United States of America

Re: COBOL interview question on PERFORM VARYING.

Post by Robert Sample »

Code is

Code: Select all

77  C                         PIC 9(04) COMP. 
77  RESULT                    PIC 9(04).      
                                              
PROCEDURE DIVISION.                           
000-START.                                    
    PERFORM VARYING C FROM 1 BY 1 UNTIL C = 6 
    ADD 1 TO RESULT                           
    END-PERFORM.                              
                                              
    DISPLAY 'C= ' C ' RESULT= ' RESULT.       
with results of

Code: Select all

C= 0006 RESULT= 0005  
The test is performed before the execution of the loop and hence these results.
utkarsh
Registered Member
Posts: 66
Joined: Fri Jun 21, 2013 10:32 pm
India

Re: COBOL interview question on PERFORM VARYING.

Post by utkarsh »

Thank you for your detailed explnation, really helpful.

Is it possible to test such cases on personal computer as these days I am on bench and don't have mainframe access.
User avatar
Robert Sample
Global Moderator
Global Moderator
Posts: 1896
Joined: Fri Jun 28, 2013 1:22 am
Location: Dubuque Iowa
United States of America

Re: COBOL interview question on PERFORM VARYING.

Post by Robert Sample »

Yes. GnuCOBOL is available to download for various platforms including Windows and Linux. GnuCOBOL has standard COBOL support, and I've run mainframe (Enterprise COBOL) program on it with no issues.
utkarsh
Registered Member
Posts: 66
Joined: Fri Jun 21, 2013 10:32 pm
India

Re: COBOL interview question on PERFORM VARYING.

Post by utkarsh »

Thanks Robert. I tried downloaded GnuCOBOL, installing it and I can not make it work. Instructions are not very clear. Could you or someone guide on how to install GnuCOBOL on laptop?
Post Reply

Create an account or sign in to join the discussion

You need to be a member in order to post a reply

Create an account

Not a member? register to join our community
Members can start their own topics & subscribe to topics
It’s free and only takes a minute

Register

Sign in

Return to “Interview Questions.”