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>Programming</strong> <strong>Language</strong> Concepts<br />

for I = 1 to N,<br />

compute<br />

MEANX as the mean,<br />

MAXIMUMX as the maximum of X(I)<br />

Like the find statement, the compute statement contains a list of variables that are set to a computed<br />

value after iteration. In this case, the values are specified by statistical names, such as mean<br />

and maximum. A compute statement has the general form:<br />

compute compute list of arithmetic expression<br />

where compute list is a list of variable and statistical names of the form variable =<br />

statistic name. The optional word the may be omitted before each statistic name, and the word<br />

as may be replaced by the equal sign. A compute statement can be controlled by more than one<br />

for phrase, and these may use logical control phrases to qualify the iteration sequence or the<br />

selection of individual variables. For example:<br />

for I = 1 to N,<br />

for J = 1 to M,<br />

with LIST(J) greater than zero<br />

compute<br />

MN as the mean of TABLE(I,J) * LIST(J)<br />

When a compute statement appears within a do loop with other statements, calculation of computed<br />

statistics, such as mean, takes place at the loop statement. If, for some reason, control is transferred<br />

out of the loop, the statistics are undefined. In the following example, computation of the<br />

indicated statistics is executed at termination of the inner do loop. Within this loop, the values<br />

X(J) are summed, and a count accumulated of the number of elements that form this sum. Before<br />

statement 4 is executed, these two values are used to compute the mean.<br />

for I = 1 to N,<br />

do<br />

statement1<br />

for J = 1 to M,<br />

do<br />

statement2<br />

compute<br />

MEANX as the mean of X(J)<br />

statement3<br />

loop<br />

statement4<br />

loop<br />

Within the inner loop, the value of MEANX is undefined.<br />

To have a compute statement controlled by several control phrases, a program is written with<br />

also phrases, as:<br />

101

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

Saved successfully!

Ooh no, something went wrong!