Code twisters: The functional loop

time to read 2 min | 206 words

This might actually be a good interview question:

int level = 10;
Func<int, int> nextLevel = new Func<int, int>(x => x--);
Func<int, bool> loopAgain = new Func<int, bool>(x => x >= 0);
while (loopAgain(level))
{
                // Process Data Logic
               
                // get the next level
                level = nextLevel(level);
}

How many times will this code loop?

With thanks to Jeff Carley for sending me this one.