2.40. Loops

The final call in a procedure is known as a tail call, and and can be indicated by a jump statement as described in the previous section, though it isn't necessary: tail calls are detected by the compiler.

There is a special kind of tail call known as a loop, in which the jump is made to the procedure containing the jump, or one or its parents.

Provided no pointers are kept to any of the frames of the procedures between the target and current frame, so that all these frames would be garbage collected, a jump to a parent can reuse the parent's storage.

This is a form of goto, except that the procedure arguments are re-initialised.

Loops are automatically detected in some cases by the compiler. An explicit loop statement may also be used:

Start felix section to tut/tutorial/tut-1.40-0.flx[1 /1 ]
     1: #line 4116 "./lpsrc/flx_tutorial.pak"
     2: //Check loops
     3: #import <flx.flxh>
     4: 
     5: proc f(x:int)
     6: {
     7:   if x == 0 goto zero;
     8:   print x; endl; loop f(x-1);
     9: zero:>
    10:   print "Zero"; jump endl;
    11: }
    12: 
    13: f(10);
    14: 
End felix section to tut/tutorial/tut-1.40-0.flx[1]
Start data section to tut/tutorial/tut-1.40-0.expect[1 /1 ]
     1: 10
End data section to tut/tutorial/tut-1.40-0.expect[1]