18.10.2014 Views

SIMSCRIPT II.5 Programming Language

SIMSCRIPT II.5 Programming Language

SIMSCRIPT II.5 Programming Language

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>SIMSCRIPT</strong> <strong>II.5</strong> <strong>Programming</strong> <strong>Language</strong><br />

program. Program control structures have been described by which logical groups of statements<br />

may be executed conditionally, or repeated under some control.<br />

There are two good reasons for developing a more elaborate program structure. First, problem solutions<br />

can require sequences of similar or identical statements to be executed at different places<br />

within a program. Although these statements can be rewritten in place each time they are needed,<br />

it is convenient to be able to combine them into groups and refer to them by symbolic names whenever<br />

required. Second, this grouping enables the separation of program elements that are logically<br />

distinct. Large programs can become too big to comprehend at a single level of complexity. Complex<br />

systems are better understood if treated in a hierarchical fashion. Dividing programs into logically<br />

related functional groups of statements allows these sections to be developed separately, and<br />

then combined at a conceptually higher level to form a whole program.<br />

These program sections are commonly termed routines. Labeled routines that are referenced by a<br />

symbolic name are called subprograms. They are distinguished as programs because they perform<br />

some specific task. They are called subprograms because they are not executed independently, but<br />

rather perform functions within the execution of a program. When execution of a subprogram is<br />

requested by another routine, control passes from this calling routine to the subprogram, along with<br />

instructions for returning control, at completion of the subprogram, to the calling routine. This hierarchical<br />

structure is not limited to one level. A subprogram may itself call upon other subprograms.<br />

Subprograms are not executed directly but are subordinate to a higher level routine. The routine at<br />

the highest level in the hierarchy is called the main routine. Every <strong>SIMSCRIPT</strong> <strong>II.5</strong> program must<br />

have one main routine, and may contain one or more subprograms. When a program is submitted<br />

for execution, the control flow is directed to the first instruction in the main routine and proceeds<br />

from there, as the logic of the main routine-subprogram package directs. All of the example programs<br />

used thus far have contained only a main routine. In succeeding paragraphs, the structure<br />

and use of subprograms will be described.<br />

Figure 2-5 shows three examples of main routine-subprogram routine organizations. The examples<br />

in this figure consist of a main routine and one or more subprograms, with arrows indicating the<br />

direction of program flow. An arrow pointing to a subprogram indicates a call on that subprogram,<br />

and an arrow pointing in the opposite direction means a return to a calling routine.<br />

52

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!