In C/C++ Language... are for loops internally compiled as while loops?
Yes, usually, basically. A for loop, written
for (a; b; c) { ... }
can be rewritten as
a;
while (b) { ...; c; }
Note that this doesn't take into account scoping and such issues, because when you translate a for to a while, scoping can't be written precisely in C++ syntax.
However, underneath, a for loop is really a series of statements and (conditional) gotos:
{
a;
goto test;
body:
...;
c;
test:
if (b) goto body:
}
except that all of it is in assembly code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With