Recursion is the preferred mechanism to implement loops in Dezyne behaviours. Dezyne supports tail-recursion. A function is allowed to call itself as the last statement before the function return. (Dezyne does not offer looping constructs like while-do, for and foreach.)

The following example illustrates the use of tail recursion to iterate over a list to process each element.

component ListConsumer
{
  provides IListProcessor pp;
  requires IIterator listIt;
  requires IListElementProcessor elmtSink;

  behaviour
  {
    void consumeList()
    {
      IIterator.IsPastEnd pastEnd = listIt.next();
      if (pastEnd == IIterator.IsPastEnd.No)
      {
        IIterator.ListElement elmt;
        listIt.get(elmt);
        elmtSink.process(elmt);
        consumeList(); // tail recursion
      }
    }

    on pp.process(list):
    {
      listIt.reset(list);
      consumeList();
    }
  }
}