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 />

4.9 Entity Control Phrases<br />

Two forms of the for statement make it possible to step through collections of entities, just as the<br />

for v = E1 to E2 by E3 statement makes it possible to step through successive elements of arrays.<br />

One form deals exclusively with permanent entities and the other deals with sets.<br />

Permanent entities, having their attributes stored as arrays, are indexed sequentially. The first entity<br />

of the permanent entity class AUTO has index 1, the second 2, ..., and the n th N.AUTO. To step<br />

through a sequence of index numbers from 1 to N.entity for a particular permanent entity class,<br />

use the control phrases:<br />

or<br />

for each entity<br />

for each entity called variable<br />

The first form is equivalent to the statement for entity = 1 to N.entity, where entity is<br />

the global variable with the same name as the entity class. Thus, the statement for each AUTO<br />

is interpreted as for AUTO = 1 to N.AUTO. The words every and all may be used in place<br />

of each, if desired.<br />

The second form above is interpreted as for variable = 1 to N.entity, where the variable<br />

named in the called phrase, instead of the global variable with the same name as the entity, takes<br />

on the sequential index values. This variable can be global or local, and cannot be subscripted.<br />

These control phrases may be combined as desired with other for, with, unless, while, and<br />

until control phrases.<br />

The following statements illustrate a typical permanent entity for phrase application.<br />

Program preamble:<br />

permanent entities<br />

every MALE has an AGE and a SALARY<br />

Main program:<br />

read N.MALE<br />

create every MALE<br />

for every MALE, read AGE(MALE), SALARY(MALE)<br />

:<br />

for every MALE with AGE(MALE) ge 21<br />

do<br />

add SALARY(MALE) to SUM<br />

add 1 to N<br />

loop<br />

:<br />

164

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

Saved successfully!

Ooh no, something went wrong!