As stated by others, the fact that C++ has implicit casting to boolean means the conditional is u--
, which will be true if the value is non-zero.
It's worth adding, that you've a false assumption in asking "where's the conditional". In both C++ and C# (and other similarly syntaxed languages) you can have an empty conditional. In this case it always evaluates to true, so the loop continues forever, or until some other condition exits it (via return
, break
, or throw
).
for(int i = 0; ; ++i)
doThisForever(i);
Indeed, any part of the for statement can be left out, in which case it's just not performed.
In general, for(A; B; C){D}
or for(A; B; C)D;
becomes:
{A}
loopBack:
if(!(B))
goto escapeLoop;
{D}
{C}
goto loopBack;
escapeLoop:
Any one or more of A, B, C or D can be left out.
As a result of this, some favour for(;;)
for infinite loops. I do because while while(true)
is more popular, I read that as "until truth ends being true", which sounds somewhat apocalyptic compared to my reading for(;;)
as "forever".
It's a matter of taste, but since I'm not the only person in the world to like for(;;)
it's worth knowing what it means.
u--
. The semi-colons are used to delimit the various parts of thefor
statement.; u-- != 0;
b
,u
,v
, etc. The only reason they were named this way is because someone wanted to look smart by making their code unreadable.do
mean in C++" - will get thousands of hits from beginners looking for a tutorial.