, ruvim, , WHILE, THEN:
: test1 ( step start
cr
begin
over +
dup . cr
dup 30 < while
dup 13 <> while
dup 17 <> while
repeat
." before 1st else" cr
else
." after 1st else" cr
then
." before 2nd else" cr
else
." after 2nd else" cr
then
;
, . , , .
:
5 1 test1
6
11
16
21
26
31
after 2nd else
ok
, :
5 3 test1
8
13
after 1st else
before 2nd else
ok
, :
5 2 test1
7
12
17
before 1st else
before 2nd else
ok
So, if someone wants to assign an action to each WHILE, this should be done as follows:
: test1 ( step start
cr
begin
over +
dup . cr
dup 30 < while
dup 13 <> while
dup 17 <> while
repeat
." exited after the 3rd while" cr
else
." exited after the 2nd while" cr
then
else
." exited after the 1st while" cr
then
;
It would be interesting how higher the scales for even more WHILE. Following is the syntax that works for 4 WHILEs:
: test1 ( step start
cr
begin
over +
dup . cr
dup 30 < while
dup 13 <> while
dup 17 <> while
dup 19 <> while
repeat
." exited after the 4th while" cr
else
." exited after the 3nd while" cr
then
else
." exited after the 2nd while" cr
then
else
." exited after the 1st while" cr
then
;
The above code has been tested in both Gforth and swapforth. An interesting question is filling out the downloadable package in various possible solutions. (For example, in CPU J1B, the depth of the returned stack is only 32 levels).
source
share