Is it considered decent form to write code like this:
int done = 0;
for (x = 0; !done; x++) {
... something involving 'x', that might end early ...
if (!(x < max))
done = 1;
}
as opposed to having to use a while loop:
int done;
x = 0;
while (!done) {
... something involving 'x', that might end early ...
if (!(x < max))
done = 1;
x++;
}
or having to break out of a for loop:
for (x = 0; x < max; x++) {
int done;
... something involving 'x', that might end early ...
if (done)
break;
}
I prefer the first one, mainly because I dislike breaking out of loops, I prefer for loops, and it still looks neat. The second one appears to me as what others would likely use.
The third one feels icky to me, but it seemed like something else that others might use as opposed to the first.
What are the merits of using one over another? Should they each be used at different times, is one generally correct, or is it just a matter of personal preference?