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>SIMSCRIPT</strong> <strong>II.5</strong> Basic Concepts<br />

and or. (In this context, a comma cannot be substituted for the word.) If E1 and E2 are logical<br />

expressions, then:<br />

E1 and E2 is true if both E1 and E2 are true<br />

E1 or E2 is true if either or both of E1 and E2 are true<br />

Compound logical expressions may contain more than two simple logical expressions, as in the logical<br />

expression:<br />

E1 and E2 or E3 and E4<br />

When more than two simple logical expressions appear in an unparenthesized compound logical expression<br />

with the operators and or or, the operator and is evaluated first. Parentheses can be used,<br />

however, to indicate a specific order of evaluation. In the absence of parentheses, the above expression<br />

is, by convention, evaluated, as though it had been written:<br />

(1) (E1 and E2) or (E3 and E4)<br />

If a program requires some other logic, the statement can be written as:<br />

(2) E1 and (E2 or E3) and E4<br />

which means something quite different. Version (1) is true either if both E1 and E2 are true or if<br />

both E3 and E4 are true. Version (2) is true if E1 is true and E4 is true, and either E2 or E3 is true.<br />

Compound logical expressions can be used with is false and is true phrases. An is false<br />

or is true phrase always applies to the logical expression preceding it. If this logical expression<br />

is compound, it must be enclosed in parentheses, as shown in the logical expression:<br />

E1 is false and (E2 or E3) is true<br />

A few simple rules that govern the writing and evaluation of logical expressions are given below.<br />

1. A logical expression enclosed in parentheses remains a logical expression.<br />

2. In the absence of parentheses, and is evaluated before or. Successive logical expressions<br />

are used as operands of and operators, and these evaluated expressions are then used as operands<br />

of or operators. Parentheses can always be used to indicate specific operator hierarchies.<br />

3. Is true and is false phrases apply to logical expressions preceding them. If such a<br />

logical expression is compound, it must be enclosed in parentheses. Otherwise, the phrase<br />

only applies to the expression adjacent to it.<br />

Some examples that illustrate the writing and evaluation of complex logical expressions are given<br />

below. In these examples, the variables I, J, K, M, and N are positive numbers; the variables Q,<br />

R, S, and T are negative numbers; and the variable Z is zero.<br />

17

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

Saved successfully!

Ooh no, something went wrong!