- Extending Qt Creator Manual
- TaskTree
- ForeverIterator
- Extending Qt Creator Manual 19.0.0-beta1

# QtTaskTree::ForeverIterator Class

class QtTaskTree::ForeverIterator

Infinite iterator to be used inside For element. More...

Header: | `#include <qtasktree.h>`
Inherits: | QtTaskTree::Iterator

- List of all members, including inherited members

Note: All functions in this class are reentrant.

## Public Functions

| ForeverIterator()

## Detailed Description

See also Iterator, RepeatIterator, UntilIterator, and ListIterator.

## Member Function Documentation

### ForeverIterator::ForeverIterator()

Constructs never ending iterator for the For (ForeverIterator()) >> Do {} construct.

Note: Be very careful if your Do body specifies parallel mode - in this case the QTaskTree may instantiate infinite number of tasks.

Example usage:

     static const int maxNumber = 10;
     const int luckyNumber = QRandomGenerator().global()->bounded(maxNumber);

     qDebug() << "Today's lucky number is:" << luckyNumber;
     qDebug() << "Let's start the drawing...";

     const auto onNumberCheck = [luckyNumber] {
         const int drawnNumber = QRandomGenerator().global()->bounded(maxNumber);
         qDebug() << "You have drawn:" << drawnNumber;
         bool won = drawnNumber == luckyNumber;
         if (won)
             qDebug() << "You have won! Congratulations!";
         return won;
     };

     const Group recipe = For (ForeverIterator()) >> Do {
         stopOnSuccess,
         timeoutTask(1s),
         QSyncTask(onNumberCheck)
     };

The possible output when the `recipe` is started by the QTaskTree:

     Today's lucky number is: 8
     Let's start the drawing...
     You have drawn: 2
     You have drawn: 2
     You have drawn: 6
     You have drawn: 7
     You have drawn: 9
     You have drawn: 8
     You have won! Congratulations!