How to resolve the algorithm Jump anywhere step by step in the COBOL programming language
How to resolve the algorithm Jump anywhere step by step in the COBOL programming language
Table of Contents
Problem Statement
Imperative programs like to jump around, but some languages restrict these jumps. Many structured languages restrict their conditional structures and loops to local jumps within a function. Some assembly languages limit certain jumps or branches to a small range. This task is to demonstrate a local jump and a global jump and the various other types of jumps that the language supports. For the purpose of this task, the jumps need not be used for a single purpose and you have the freedom to use these jumps for different purposes. You may also defer to more specific tasks, like Exceptions or Generator. This task provides a "grab bag" for several types of jumps. There are non-local jumps across function calls, or long jumps to anywhere within a program. Anywhere means not only to the tops of functions! These jumps are not all alike. A simple goto never touches the call stack. A continuation saves the call stack, so you can continue a function call after it ends.
Use your language to demonstrate the various types of jumps that it supports. Because the possibilities vary by language, this task is not specific. You have the freedom to use these jumps for different purposes. You may also defer to more specific tasks, like Exceptions or Generator.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Jump anywhere step by step in the COBOL programming language
Source code in the cobol programming language
IDENTIFICATION DIVISION.
PROGRAM-ID. jumps-program.
* Nobody writes like this, of course; but...
PROCEDURE DIVISION.
* You can jump anywhere you like.
start-paragraph.
GO TO an-arbitrary-paragraph.
yet-another-paragraph.
ALTER start-paragraph TO PROCEED TO a-paragraph-somewhere.
* That's right, folks: we don't just have GO TOs, we have GO TOs whose
* destinations can be changed at will, from anywhere in the program,
* at run time.
GO TO start-paragraph.
* But bear in mind: once you get there, the GO TO no longer goes to
* where it says it goes to.
a-paragraph-somewhere.
DISPLAY 'Never heard of him.'
STOP RUN.
some-other-paragraph.
* You think that's bad? You ain't seen nothing.
GO TO yet-another-paragraph.
an-arbitrary-paragraph.
DISPLAY 'Edsger who now?'
GO TO some-other-paragraph.
END PROGRAM jumps-program.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 province PICTURE IS 99 VALUE IS 2.
PROCEDURE DIVISION.
GO TO quebec, ontario, manitoba DEPENDING ON province.
* Jumps to section or paragraph named 'ontario'.
You may also check:How to resolve the algorithm Program name step by step in the Lingo programming language
You may also check:How to resolve the algorithm Copy stdin to stdout step by step in the Commodore BASIC programming language
You may also check:How to resolve the algorithm Plot coordinate pairs step by step in the Liberty BASIC programming language
You may also check:How to resolve the algorithm Binary digits step by step in the R programming language
You may also check:How to resolve the algorithm Start from a main routine step by step in the zkl programming language