Instruction manual

MDP
PRODUCT
INFORMATION
Issue 3 - Vol 2
USER
GROUP
NEWS
NESTED
IFS
Since
the
statement
rollowing an
ir
or
and
else
can be any
Rational
statement,
this leads immediately
to
the
possibility or another
ir
or
else
As a userul example, consider this problem: The
variable"
r
is
to be
set
to
-1 ir
"x"
is
less
than
zero; to + 1 ir "x"
is
greater
than
100, and
to
0 otherwise.
Then
in
Rational,
we
write:
ir
(x
< 0)
r=-1
else if
(x
> 100)
r=+1
else
r=o
In general, the
structure
ir (
...
)
else if (
...
)
else if (
...
)
else
provides a way to specify the choice
of
exactly one
of
several alternatives.
THE
SWITCH
STATKMENT
The
switch
statement
provides a clean way
to
express multi-way branches which branch on
the
value
of
some
integer-valued expression.
The
syntax
is:
switch (expression) {
case
exprl:
statements
case expr2, expr3:
statements
deCault
statements
Each case
is
Collowed
by a list
oC
comma-separated integer expressions.
The
expression inside
switch
is
compared
against
the
case expression
exprl,
expr2,
and
so
on until one matches,
at
which time
the
statements
following the
case are executed.
If
no cases
match
the
expression,
and
there
is
a
derault
section,
the
statements
with
it
are
done; if there
is
no
derault
nothing is done. (Those familiar with C should beware since the behavior is
not
the
same as
the
C
switch).
THE
WHILE
STATEMENT
RATFOR
provides a
while
statement;
which is simply a loop:
while
some
condition
is
true,
repeat
this
group
or
statements.
For
example:
i = 1
while
(i
< = 100) {
i=i+l
}
6
TEKTRONIX
December
lQS3