Hi all,
I am confused by a question in the Head First C# book, the task is to identify how many times a loop will loop (is this called iterations?). I have worked out a few but one is really confusing me. I am currently 'paper coding' as I'm at work so I can't watch the variable but an explanation would be great as I'm really puzzled. This one asks how many times the statement 'j = j - i;' will be executed.
int j = 2;
for (int i = 1; i < 100;
i = i * 2)
{
j = j - i;
while (j < 25)
{
j = j + 5;
}
}
I have come up with many answers and none of them are what the book tells me it should be. I think I may be getting confused on what the values are on the very first execution and this perhaps is making me go wrong. Any advice would be greatly appreciated and hopefully set me up for the next one which looks harder.