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

When a let statement is executed, the current values of the variables on the right of the equal symbol<br />

(=) are used to compute the value of the arithmetic expression. This value is then assigned to<br />

the variable on the left of the equal symbol.<br />

Used in this way, in conjunction with the word let, the equal symbol is an assignment operator.<br />

In the statement:<br />

let X = Y * 2<br />

the value of the expression Y * 2 is computed and assigned to the variable X. The previous value<br />

of X is replaced by the new value; and in:<br />

let X = X + 1<br />

a new value of X is computed by adding 1 to the current value of X and assigning this new value to<br />

X. Use of the word let is optional. That is, the = operator is enough for assigning an expression to<br />

a variable.<br />

1.7 Specialized Computation Statements<br />

Because addition and subtraction are such frequently used operations, two special statements,<br />

combining both expression evaluation and assignment operations, may be used. The add and<br />

subtract statements are used to add or subtract the value of an arithmetic expression to or from a<br />

program variable. The statement forms are:<br />

add arithmetic expression to variable<br />

subtract arithmetic expression from variable<br />

The statements are equivalent to the let statements:<br />

let variable = variable + arithmetic expression<br />

let variable = variable - arithmetic expression<br />

The add and subtract statements have the virtues of being easy to write and being straightforward<br />

in meaning. Some examples of these statements are:<br />

add 1 to COUNTER<br />

add ITEM * COST to BILL<br />

subtract 3 * X + 6 * Y from Z<br />

subtract COST from CASH<br />

1.8 Displaying the Results of Computation<br />

The print statement was used in the first example in paragraph 1 to display the result of a computation.<br />

This statement may be used either to display some predefined text, or to display both predefined<br />

text together with the current values of program variables or arithmetic expressions, as in:<br />

print I lines as follows<br />

6

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

Saved successfully!

Ooh no, something went wrong!