Flow-control structures: Difference between revisions

→‎{{header|COBOL}}: Added ALTER, but only because it exists, not to encourage its use
(→‎{{header|COBOL}}: Added ALTER, but only because it exists, not to encourage its use)
Line 360:
* *> Handle invalid thing...
END-EVALUATE</lang>
 
=== ALTER ===
The much maligned altered GO.
 
''The ALTER statement is now obsolete and not even mentioned in the COBOL 2014 standard.''
 
If anyone wonders why this was ever designed into a language, you have to look back to the days of 8K RAM, multi-million dollar computers, and source code that was entered on punch cards, one line per card. Think of physically recoding an entire deck of punch cards (say even 6,000 lines worth) versus ALTERing a few paragraphs, that jump to new code at the end of the deck, and you may see one small reason why this was ever built into early versions of COBOL. Then ponder what the state of the code would be after three or four (or fifty) such patches, and then see why ALTER was deemed obsolete shortly after terminals and disk become the common way of entering programs.
 
Then pause to think about the fact that some COBOL code, written before ALTER went out of fashion, is still in production, to understand why it was implemented in GnuCOBOL, a relatively new COBOL dialect, still in development as of 2016 (along with other modern COBOL implementations, that support COBOL 2014, and yet continue to support language constructs that date all the way back to COBOL-60).
 
{{works with|GnuCOBOL}}
<lang COBOL>
identification division.
program-id. altering.
 
procedure division.
main section.
 
*> And now for some altering.
contrived.
ALTER story TO PROCEED TO beginning
GO TO story
.
 
*> Jump to a part of the story
story.
GO.
.
 
*> the first part
beginning.
ALTER story TO PROCEED to middle
DISPLAY "This is the start of a changing story"
GO TO story
.
 
*> the middle bit
middle.
ALTER story TO PROCEED to ending
DISPLAY "The story progresses"
GO TO story
.
 
*> the climatic finish
ending.
DISPLAY "The story ends, happily ever after"
.
 
*> fall through to the exit
exit program.
</lang>
{{out}}
<pre>
prompt$ cobc -xj altering.cob
This is the start of a changing story
The story progresses
The story ends, happily ever after
</pre>
 
=== INVOKE ===
Anonymous user