Possible Duplicate:
How to write a `for` loop over bool values (false and true)
I want to perform the same task twice with bool flag true first and false second. Is there an elegant way to do that (maybe using a loop)?
My idea was to do something like the following but this is a way too complicated.
bool flag = true;
for(int i = 0; i < 2; ++i, flag = !flag)
{
// ...
}
I figured out a nice way using a do-while-loop.
Since the code in a do-while-loop is executed at least once, I can toggle the flag at the end and get exactly two runs.