Saturday, November 19, 2011

GO TO Usage



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.
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!

No comments:

Post a Comment