6.2.0700 AGAIN CORE EXT

Interpretation:

Interpretation semantics for this word are undefined.

Compilation:

( C: dest -- )

Append the run-time semantics given below to the current definition, resolving the backward reference dest.

Run-time:

( -- )

Continue execution at the location specified by dest. If no other control flow words are used, any program code after AGAIN will not be executed.

See:

Rationale:

Typical use: : X ... BEGIN ... AGAIN ... ;

Unless word-sequence has a way to terminate, this is an endless loop.

ContributeContributions

EricBlakeavatar of EricBlake [385] Suggested testSuggested Testcase2025-07-21 02:57:44

It is possible to test AGAIN without an infinite loop if combined with the tools set AHEAD and CS-ROLL, as in:

: [1cs-roll] 1 CS-ROLL ; IMMEDIATE 
T{ : GI7 0 BEGIN (cs: -- d1 )
  111  ( first pass: -- 0 111 ; second pass: -- 0 111 444 111)
  OVER IF ( cs: -- d1 o2 )
    222 ( second pass only: -- 0 111 444 111 222 )
    AHEAD ( cs: -- d1 o2 o3 )
    [1cs-roll] ( cs: -- d1 o3 o2 )
    333 \ unreachable
  THEN ( cs: -- d1 o3 ) \ resolve the IF
   444 ( first pass only: -- 0 111 444 )
   [1cs-roll] ( cs: -- o3 d1 )
  AGAIN ( cs: -- o3 ) \ resolve the BEGIN
  555 \ unreachable
  THEN ( cs: -- ) \ resolve the AHEAD
  666 ( -- 0 111 444 111 222 666 )
; -> }T
T{ GI7 -> 0 111 444 111 222 666 }T

It would also be possible to test breaking a BEGIN-AGAIN loop with throw in the loop body, using the exception word set.

Reply New Version