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>SIMSCRIPT</strong> <strong>II.5</strong> <strong>Programming</strong> <strong>Language</strong><br />

8. A subscripted local variable that does not appear in a define statement within a routine<br />

has its dimensionality defined by its first use. That is, even if a routine's normally condition<br />

is zero-dimensional, the statement let X(1) = 0 implicitly defines X as one-dimensional.<br />

However, the array must still be reserved before its first use.<br />

9. Definition statements for local variables placed at the head of a routine are not preceded by<br />

preamble and followed by end, as are similar statements in a program preamble. In fact,<br />

normally and define statements can be used anywhere within a routine, although it is<br />

good practice to place them before any instruction statements.<br />

2.12 Routine Arguments<br />

Global variables provide one mechanism by which values may be communicated between program<br />

routines. A preferred way is through routine arguments. Arguments are values that are explicitly<br />

transmitted between calling and called routines. By making the transmission of values between routines<br />

explicit, rather than using global variables, the logical interaction between these routines may<br />

be emphasized, reducing the risk of inadvertent interaction. Arguments represent variables that behave<br />

as local variables of a called routine, but which may either receive initial values each time the<br />

routine is called, termed given arguments, or may be used as yielded arguments to transmit result<br />

values back to the calling routine. In the case of given arguments, the initial values are supplied<br />

by the calling routine. Numeric yielded arguments are initialized to zero, as for normal local<br />

variables.<br />

When a routine definition is written, those local variables that are to be arguments of the routine<br />

are listed in the routine definition statement. This definition list is termed the formal argument list.<br />

When a routine with arguments is called, the values that are to be used to initialize or receive values<br />

from the argument variables are listed in order corresponding to the formal argument list in the routine<br />

definition. The called routine may return values to a calling routine by assigning the values to<br />

those of its argument variables defined to be yielded arguments. Those yielded arguments not<br />

assigned a value in the routine retain the initialized values of zero. The general form of a routine<br />

definition is:<br />

routine name given given argument list yielding yield argument list<br />

Consider, for example, the common square-root calculation discussed above. A routine to evaluate<br />

the square root of a number might be written:<br />

60

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

Saved successfully!

Ooh no, something went wrong!