WHILE

Interpretation:

Interpretation semantics for this word are undefined.

Compilation:

( C: dest -- orig dest )

Put the location of a new unresolved forward reference orig onto the control flow stack, under the existing dest. Append the run-time semantics given below to the current definition. The semantics are incomplete until orig and dest are resolved (e.g., by REPEAT).

Run-time:

( x -- )

If all bits of x are zero, continue execution at the location specified by the resolution of orig.

See:

Rationale:

Typical use: : X ... BEGIN ... test WHILE ... REPEAT ... ;

Testing:

T{ : GI3 BEGIN DUP 5 < WHILE DUP 1+ REPEAT ; -> }T
T{ 0 GI3 -> 0 1 2 3 4 5 }T
T{ 4 GI3 -> 4 5 }T
T{ 5 GI3 -> 5 }T
T{ 6 GI3 -> 6 }T

T{ : GI5 BEGIN DUP 2 > WHILE 
      DUP 5 < WHILE DUP 1+ REPEAT 
      123 ELSE 345 THEN ; -> }T

T{ 1 GI5 -> 1 345 }T
T{ 2 GI5 -> 2 345 }T
T{ 3 GI5 -> 3 4 5 123 }T
T{ 4 GI5 -> 4 5 123 }T
T{ 5 GI5 -> 5 123 }T

ContributeContributions

MatteoVitturiavatar of MatteoVitturi There is an error in testingComment2021-08-20 20:54:31

GI5 don't compile correctly. To cope with subsequent test it should be as follow.

T{ : GI5 DUP 2 > IF BEGIN 
         DUP 5 < WHILE DUP 1+ REPEAT 
         123 ELSE 345 THEN ; -> }T

MatteoVitturiavatar of MatteoVitturiNew Version

Hide differences

GI5 don't compile correctly. To cope with subsequent test it should be as follow.

GI5 don't compile correctly. To cope with subsequent tests it should be as follow.

T{ : GI5 DUP 2 > IF BEGIN 
         DUP 5 < WHILE DUP 1+ REPEAT 
         123 ELSE 345 THEN ; -> }T

BerndPaysanavatar of BerndPaysan

GI5 tests multiple WHILEs, and compiles correctly on systems that implement WHILE and REPEAT correctly. You are supposed to resolve one WHILE (the latest) at REPEAT, and leave the others to a matching ELSE or THEN.

Closed

flaagelavatar of flaagel

This is a tricky implementation point. Z79Forth also choked on this particular piece of the test suite. Not that it is really a problem since my primary allegiance is 79-STANDARD but I still believe that ANS compliance, whenever achievable, is desirable. This is now fixed and I will release the updated code on GitHub soon.

Reply New Version