Home > Software > Mainframe > Cobol
Interview Questions   Tutorials   Discussions   Programs   

Cobol - What is the difference between go to and perform statement?




1449
views
asked mar August 3, 2014 02:06 AM  

What is the difference between go to and perform statement?


           

1 Answers



 
answered By Mswami   0  
GO TO will never give the control back where as PERFORM returns the control.

In a structured top-down programming GO TO is not preferable. It offers permanent control transfer to another paragraph and the chances of logic errors is much greater with GO TO than PERFORM. The readability of the program will also be badly affected.
But still GO TO can be used within the paragraphs being performed. i.e. When using the THRU option of PERFORM statement, branches or GO TO statements, are permitted as long as they are within the range of named paragraphs.

Example:

  PERFORM 100-STEP1 THRU STEP-4
  ..
100-STEP-1.
  ADD A TO B GIVING C.
  IF D = ZERO DISPLAY ‘MULTIPLICATION NOT DONE’
         GO TO 300-STEP3
  END-IF.
200-STEP-2.
  MULTIPLY C BY D.
300-STEP-3.
  DISPLAY ‘VALUE OF C:’ C.
Here GO TO used within the range of PERFORM. This kind of Controlled GO TO is fine with structured programming also!!.

flag   
   add comment

Your answer

Join with account you already have

FF

Preview


Ready to start your tutorial with us? That's great! Send us an email and we will get back to you as soon as possible!

Alert