2016 Update
This commit is contained in:
parent
948b86eafa
commit
dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions
|
|
@ -1,5 +1,14 @@
|
|||
{{Control Structures}}
|
||||
In this task, we document common flow-control structures.
|
||||
One common example of a flow-control structure is the <tt>goto</tt> construct.
|
||||
Note that [[Conditional Structures]] and [[Iteration|Loop Structures]]
|
||||
have their own articles/categories.
|
||||
|
||||
;Task:
|
||||
Document common flow-control structures.
|
||||
|
||||
One common example of a flow-control structure is the <big><code> goto </code></big> construct.
|
||||
|
||||
Note that [[Conditional Structures]] and [[Iteration|Loop Structures]] have their own articles/categories.
|
||||
|
||||
|
||||
;Related tasks:
|
||||
* [[Conditional Structures]]
|
||||
* [[Iteration|Loop Structures]]
|
||||
<br><br>
|
||||
|
|
|
|||
|
|
@ -1,23 +1,38 @@
|
|||
PROGRAM-ID. Perform-Example.
|
||||
identification division.
|
||||
program-id. altering.
|
||||
|
||||
PROCEDURE DIVISION.
|
||||
Main.
|
||||
PERFORM Moo
|
||||
PERFORM Display-Stuff
|
||||
PERFORM Boo THRU Moo
|
||||
procedure division.
|
||||
main section.
|
||||
|
||||
GOBACK
|
||||
.
|
||||
*> And now for some altering.
|
||||
contrived.
|
||||
ALTER story TO PROCEED TO beginning
|
||||
GO TO story
|
||||
.
|
||||
|
||||
Display-Stuff SECTION.
|
||||
Foo.
|
||||
DISPLAY "Foo " WITH NO ADVANCING
|
||||
.
|
||||
*> Jump to a part of the story
|
||||
story.
|
||||
GO.
|
||||
.
|
||||
|
||||
Boo.
|
||||
DISPLAY "Boo " WITH NO ADVANCING
|
||||
.
|
||||
*> the first part
|
||||
beginning.
|
||||
ALTER story TO PROCEED to middle
|
||||
DISPLAY "This is the start of a changing story"
|
||||
GO TO story
|
||||
.
|
||||
|
||||
Moo.
|
||||
DISPLAY "Moo"
|
||||
.
|
||||
*> 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.
|
||||
|
|
|
|||
|
|
@ -0,0 +1,23 @@
|
|||
PROGRAM-ID. Perform-Example.
|
||||
|
||||
PROCEDURE DIVISION.
|
||||
Main.
|
||||
PERFORM Moo
|
||||
PERFORM Display-Stuff
|
||||
PERFORM Boo THRU Moo
|
||||
|
||||
GOBACK
|
||||
.
|
||||
|
||||
Display-Stuff SECTION.
|
||||
Foo.
|
||||
DISPLAY "Foo " WITH NO ADVANCING
|
||||
.
|
||||
|
||||
Boo.
|
||||
DISPLAY "Boo " WITH NO ADVANCING
|
||||
.
|
||||
|
||||
Moo.
|
||||
DISPLAY "Moo"
|
||||
.
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
...
|
||||
ASSIGN 1101 to WHENCE !Remember my return point.
|
||||
GO TO 1000 !Dive into a "subroutine"
|
||||
1101 CONTINUE !Resume.
|
||||
...
|
||||
ASSIGN 1102 to WHENCE !Prepare for another invocation.
|
||||
GO TO 1000 !Like GOSUB in BASIC.
|
||||
1102 CONTINUE !Carry on.
|
||||
...
|
||||
Common code, far away.
|
||||
1000 do something !This has all the context available.
|
||||
GO TO WHENCE !Return whence I came.
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
ASSIGN 2000 TO WHENCE !Deviant "return" from 1000 to invoke 2000.
|
||||
ASSIGN 1103 TO THENCE !Desired return from 2000.
|
||||
GO TO 1000
|
||||
1103 CONTINUE
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
SUBROUTINE FRED(X,*,*) !With placeholders for unusual parameters.
|
||||
...
|
||||
RETURN !Normal return from FRED.
|
||||
...
|
||||
RETURN 2 !Return to the second label.
|
||||
END
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
XX:DO WHILE(condition)
|
||||
statements...
|
||||
NN:DO I = 1,N
|
||||
statements...
|
||||
IF (...) EXIT XX
|
||||
IF (...) CYCLE NN
|
||||
statements...
|
||||
END DO NN
|
||||
END DO XX
|
||||
Loading…
Add table
Add a link
Reference in a new issue