What would be the equivalent of doing the following for loop as a while loop?
for (int i=0;i<10;i++)
{
...
}
At first I thought the following would work:
int n = 0;
while (n++ <= 10)
{
...
}
But it seems that the post-increment happens before the first while loop is entered, and so I'd need to set n=-1 to adjust for that. Is there a closer way to re-write a for loop into a while loop (without the do) ?
int n = 10; while(n--) {...}will work in reverse. However, any such rewrite will extend the scope and lifetime ofnbeyond the loops.