Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Special pages
Niidae Wiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
COBOL
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=====Control flow===== COBOL's [[conditional (computer programming)|conditional statements]] are {{code|IF}} and {{code|EVALUATE}}. {{code|EVALUATE}} is a [[switch statement|switch-like statement]] with the added capability of evaluating multiple values and conditions. This can be used to implement [[decision table]]s. For example, the following might be used to control a [[CNC lathe]]: <!-- a more common appliance would be more suitable. --> <syntaxhighlight lang="cobolfree"> EVALUATE TRUE ALSO desired-speed ALSO current-speed WHEN lid-closed ALSO min-speed THRU max-speed ALSO LESS THAN desired-speed PERFORM speed-up-machine WHEN lid-closed ALSO min-speed THRU max-speed ALSO GREATER THAN desired-speed PERFORM slow-down-machine WHEN lid-open ALSO ANY ALSO NOT ZERO PERFORM emergency-stop WHEN OTHER CONTINUE END-EVALUATE </syntaxhighlight> The {{code|PERFORM}} statement is used to define loops which are executed {{em|until}} a condition is true (not {{em|while}} true, which is more common in other languages). It is also used to call procedures or ranges of procedures (see the [[#Procedures|procedures section]] for more details). {{code|CALL}} and {{code|INVOKE}} call subprograms and methods, respectively. The name of the subprogram/method is contained in a string which may be a literal or a data item.{{sfn|ISO/IEC JTC 1/SC 22/WG 4|2014|loc=Β§Β§ 14.9.4, 14.9.22}} Parameters can be passed [[call by reference|by reference]], by content (where a copy is passed by reference) or [[call by value|by value]] (but only if a [[function prototype|prototype]] is available).{{sfn|ISO/IEC JTC 1/SC 22/WG 4|2014|loc=Β§ D.6.5.2.2}} {{code|CANCEL}} unloads subprograms from memory. {{code|GO TO}} causes the program to jump to a specified procedure. The {{code|GOBACK}} statement is a [[return statement]] and the {{code|STOP}} statement stops the program. The {{code|EXIT}} statement has six different formats: it can be used as a return statement, a [[break statement]], a [[continue statement]], an end marker or to leave a procedure.{{sfn|ISO/IEC JTC 1/SC 22/WG 4|2014|loc=Β§ 14.9.13.1}} [[Exception handling|Exceptions]] are raised by a {{code|RAISE}} statement and caught with a handler, or ''{{dfn|declarative}}'', defined in the {{code|DECLARATIVES}} portion of the procedure division. Declaratives are sections beginning with a {{code|USE}} statement which specify the errors to handle. Exceptions can be names or objects. {{code|RESUME}} is used in a declarative to jump to the statement after the one that raised the exception or to a procedure outside the {{code|DECLARATIVES}}. Unlike other languages, uncaught exceptions may not terminate the program and the program can proceed unaffected.
Summary:
Please note that all contributions to Niidae Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Encyclopedia:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Search
Search
Editing
COBOL
(section)
Add topic