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.

3. Input/Output Concepts<br />

3.1 Introduction<br />

This chapter introduces some additional control structures provided by <strong>SIMSCRIPT</strong> <strong>II.5</strong>, and then<br />

describes in detail the full input and output formatting facilities available in the language.<br />

3.2 A Search Capability<br />

It is often necessary to search among a number of variable values for one satisfying some stated<br />

condition. The find statement provides a means of specifying some such condition and is used, in<br />

conjunction with a for control phrase, to search a group of values for the first value meeting the<br />

specification. The statement:<br />

for I = 1 to N,<br />

with X(I) * Y(I) greater than LIMIT,<br />

find BIG = the first I<br />

is a compound statement composed of a qualified for phrase and a find statement. The for<br />

phrase steps the variable I through the sequence of values 1 ,2, ..., N,; the with phrase specifies<br />

that only those values of I for which X(I) * Y(I) is greater than LIMIT are eligible for consideration;<br />

the find statement specifies that the repetition is to terminate as soon as such a value<br />

is found, assigning this value to the designated variable, BIG. The words the and first are optional<br />

after the equal sign. The statements:<br />

find BIG = the first I<br />

find BIG = first I<br />

find BIG = I<br />

are equivalent, and illustrate alternate forms of the basic find statement:<br />

find variable = arithmetic expression<br />

Any variable, subscripted or otherwise, may be designated. When the first index value is found for<br />

which the logical expression in the for phrase is true, the arithmetic expression is evaluated and<br />

assigned to the variable. Thus, in the above example the value of the expression I is assigned to the<br />

variable BIG when a value of I is found for which X(I) * Y(I) is greater than LIMIT. As the<br />

search is always terminated at the first suitable value encountered, a backward-iterating for phrase<br />

may be used to find the last such value in a group.<br />

A special form of the if statement may be used in conjunction with the find statement. This<br />

provides for alternative actions to be selected based on the outcome of the search. An if statement<br />

appended to a find statement may test for success or otherwise using the logical conditions:<br />

if found<br />

99

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

Saved successfully!

Ooh no, something went wrong!