23 lines
472 B
Plaintext
23 lines
472 B
Plaintext
doc{
|
|
A couple of helper functions to make the rest of the
|
|
code more readable.
|
|
}doc
|
|
|
|
: rand ( -n ) random 20 mod ;
|
|
: . ( n- ) putn space ;
|
|
|
|
doc{
|
|
One approach is to use a simple repeat/again loop, and
|
|
a conditional exit. For instance:
|
|
}doc
|
|
|
|
: foo ( - )
|
|
repeat rand dup . 10 = if; rand . again ;
|
|
|
|
doc{
|
|
The other approach uses a structured while loop with the
|
|
second printing handled by a conditional clause.
|
|
}doc
|
|
|
|
[ rand dup . 10 <> [ [ rand . ] ifTrue ] sip ] while
|