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?
Use of for loop conditional statement unrelated to iterating variable
c;code quality;loops
Consider the following:int done = 0;for (i = 0; !done && i < max; ++i) {    // ... something involving 'i', that might end early ...}My personal preference here is to keep the break condition in one point.  If you add a second if clause that breaks, you risk to skip over that logic when you or another programmer reads over it later.  As a general rule, you should avoid using breaks in loops unless it is unavoidable.  In a certain sense, it is the equivalent of a goto.  In this way the number of lines is minimized and, dare I say it, the code looks cleaner this way.  Note that I used i in the place of x because if it is an index, as a rule, I tend to prefer i, though you can use whatever you prefer.  In general, if I have to cycle through a list or array of items, I will use a for loop, even if, as in your case, you may have conditional rules for exiting the loop.  I will use a while loop if I am iterating through a list or array of items and index/position in list or array is not important.  I will also use while if there is no predetermined end to the loop.  That doesn't mean there isn't one, but rather that I don't know when the while loop will end before I begin.  I will generally avoid do ... while as more often than not, the very reason you cannot continue due to your break condition is what the logic contained within will depend on, and so you usually end up with something like:condition = 0;do {    if(!condition) {       // Perform some operation and possibly set condition to 1.    }} while (!condition);I tend to at that point break the operation into a function of its own:while(performOperation()) ;...int performOperation() {    // Set result to value indicating success or failure    return result;  }Hope that helps!