# While - HP -28S Manual

Suppose that you want to completely evaluate
I
A
+B
I ,
where A con-
tains
I
P +G!
I
and P contains 2. The first evaluation of the loop clause
returns
I
A
+B
I
and
I
P
+0 +B
I •
These expressions are not the same, so
the loop clause is evaluated a second time, returning
I
P +0 +B
I
and
I
2 +G! +B
I •
These expressions are not the same, so the loop clause is
evaluated a third time, returning
I
2 +0 +B
I
and
I
2 +G! +B
I •
These ex-
pressions are the same, so the loop structure ends.
The effect of this example is similar to the effect of .... NUM, except
... NUM causes an error if a name is undefined. For a more versatile
version of this example, see "MULTI (Multiple Execution)" on page
253.
WHILE ... REPEAT ... END
The following example takes any number of vectors from the stack
and adds them to the current statistics matrix. Since
it
needs to test
whether the object in level 1 is a vector
before
this example uses WHILE ... REPEAT ... END.
WHILE DUP TYPE 3
==
REPEAT I+ END
This structure works as follows:
1. The test clause
DUP TYPE
3
==
is evaluated, leaving a flag on
the stack. The flag indicates whether the object in level 2 is a
real vector.
2.
The flag is taken from the stack. Its value determines whether
the loop clause is executed .
• If the flag is true, the loop clause
I +
vector to the current statistics matrix, and steps (1) and (2) are
repeated.
• If the flag is false, the loop structure ends.
Note that WHILE ... REPEAT ... END ends when the flag is false,
but DO ... UNTIL ... END ends when the flag is true. If you need to
change the truth value of a test clause, add NOT as the last com-
mand: WHILE ... NOT REPEAT or UNTIL ... NOT END.
For another example of WHILE ... REPEAT ... END, see "PAD (Pad
With Leading Spaces)" on page 257.
232
26: Program Structures  