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.

Modelling Concepts<br />

4.14.3 An Analysis of Prime Numbers<br />

Program 4-3.<br />

_______________________________________________________________________________<br />

preamble<br />

normally mode is integer<br />

the system owns the PRIMESET<br />

temporary entities<br />

every PRIME has a VALUE and belongs to the PRIMESET<br />

end<br />

main<br />

read N<br />

for I = 2 to N,<br />

do<br />

''CREATE PRIME NUMBERS<br />

for each PRIME in PRIMESET<br />

with MOD.F(I, VALUE) eq 0<br />

find the first case<br />

if none<br />

create a PRIME<br />

let VALUE.. = I<br />

file PRIME in PRIMESET<br />

always<br />

loop<br />

for each I of PRIMESET<br />

with S.PRIMESET(I) ne 0<br />

compute MAX = the max(I) of VALUE(S.PRIMESET(I)) - VALUE(I)<br />

print 2 lines with N.PRIMES, VALUE(MAX),<br />

VALUE(S.PRIMESET(MAX)) thus<br />

MAXIMUM GAP AMONG THE FIRST **** PRIMES<br />

OCCURS BETWEEN **** AND ****<br />

stop<br />

end<br />

_______________________________________________________________________________<br />

4.14.4 Dynamic Definition and Use of Attributes<br />

Because the notation for subscripting array elements is the same as that used for entity attributes,<br />

there are obvious difficulties in attempting to directly reference elements of an array that is an attribute<br />

of a temporary entity. In fact, this cannot be done. It is possible, however, to associate array<br />

attributes with entities, through some explicit programming. The following statements illustrate<br />

how to create, use, and destroy array attributes.<br />

181

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

Saved successfully!

Ooh no, something went wrong!