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

An expression is written as a string of variable names, constants, arithmetic operators, and parentheses.<br />

Any number of spaces from zero upward may be used to separate the parts of an expression.<br />

Therefore, A+B, A+ B, A + B and A +B are treated identically. The exponentiation operator,<br />

**, is treated as a single unit and no spaces may appear between its two asterisks. Some example<br />

expressions are given in table 1-2.<br />

Table 1-2. Sample Mathematical Expressions<br />

_______________________________________________________________________________<br />

Expression<br />

PRICE<br />

Comment<br />

A variable is itself an expression<br />

53 A constant is also an expression<br />

(PRICE)<br />

Parentheses are optional<br />

DUEIN - DUEOUT<br />

PRICE * QUANTITY<br />

PRICE * (ORDER - SALES)<br />

Parentheses change precedence order<br />

A + B + C + D<br />

X ** 2 In mathematical notation, this is X 2<br />

A + X ** 2 + X ** 4<br />

Equivalent to the following:<br />

A + (X ** 2) + (X ** 4)<br />

X + Y / Z<br />

This means<br />

X + (Y/Z),<br />

not:<br />

(X + Y)/Z<br />

- A ** B This means -(A B ), not (-A) B<br />

_______________________________________________________________________________<br />

1.6 Computing Variable Values<br />

One way of assigning a value to a program variable is to use a read statement. Another way is to<br />

use a let statement. The general form of this statement is:<br />

let variable = expression<br />

as in the statements:<br />

let X = 0<br />

let X = (Y + 1)/15<br />

let PRICE = QUANTITY * SALES.PRICE<br />

let BALANCE = STOCK - PURCHASE<br />

let UNIT.COST = TOTAL.COST / NUMBER.OF.UNITS<br />

let AREA = 3.14 * RADIUS ** 2<br />

5

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

Saved successfully!

Ooh no, something went wrong!