4 ms·
I'm quite familiar with C, but I don't see the difference between the while and for loops in the trivia box on article 2 of the series. I would expect the whil
by nitrogen 16y ago
I'm quite familiar with C, but I don't see the difference between the while and for loops in the trivia box on article 2 of the series.
I would expect the while loop to compile something like this:
while(condition)
{
// stuff
i++;
}
becomes
loop:
if(!condition)
goto end;
// stuff
i++;
goto loop;
end:
I would expect the for loop to do this:
for(;condition;i++) {
// stuff
}
becomes
loop:
if(!condition)
goto end;
// stuff
i++;
goto loop;
end:
So what's actually going on?
- RiderOfGiraffes 16y agoConsider the effect of a "continue" statement in the "stuff" section.
- nitrogen 16y agoAh, thanks. It makes perfect sense now.