18.10.2014 Views

SIMSCRIPT II.5 Programming Language

SIMSCRIPT II.5 Programming Language

SIMSCRIPT II.5 Programming Language

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>Programming</strong> <strong>Language</strong> Concepts<br />

complete program may have only one main routine. The main routine, like all other program sections,<br />

should be terminated by the word end.<br />

A subprogram definition statement precedes the statements belonging to each subprogram and:<br />

1. Declares that the statements following are part of a subprogram<br />

2. Names to the subprogram<br />

3. Sets up a communication mechanism for passing data to and from the subprogram.<br />

Each subprogram has a name, which is declared in the subprogram definition statement that precedes<br />

the statements composing the body of the subprogram. Subprogram names follow the same<br />

naming conventions as variables (see paragraph 2.1). Each variable and subprogram name must be<br />

unique. A subprogram definition of the simplest form is:<br />

routine name<br />

The optional words to and for are allowed after the word routine. Thus, a program to calculate<br />

square roots might be named SQUARE.ROOT and could be defined by the statements:<br />

routine SQUARE.ROOT<br />

or<br />

routine for SQUARE.ROOT<br />

or it might be named TAKE.SQUARE.ROOT and be defined by the statement:<br />

routine to TAKE.SQUARE.ROOT<br />

As the words to and for are optional, there are obvious ambiguities in using the words to and for<br />

as subprogram names.<br />

Execution of the statements within a subprogram may be requested from another routine by referencing<br />

the subprogram name. Such reference is known as calling the subprogram and commonly<br />

takes the form:<br />

call name<br />

This is the simplest form of the call statement. Additions to this statement and alternative routine<br />

references will be discussed in following paragraphs.<br />

Each subprogram is defined with a routine statement. As for other program sections, an end<br />

statement indicates the physical end of the routine. The statements in between constitute the body<br />

of the subprogram. The logical end of a routine, rather than the physical end, is normally indicated<br />

by the special statement:<br />

return<br />

55

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

Saved successfully!

Ooh no, something went wrong!