To my way of thinking, a for loop is used to iterate over a known or determinable range.
String[] names = //something;
for ( int i = 0; i < names.length; i++ ) { //do stuff }
which is equivalent (scoping of i aside) to :
String[] names = //something;
int i = 0;
while (i < names.length )
{
// do stuff
i++;
}
In other words, the for loop is simply a (highly useful) syntactic sugar for a commonly used while construct.
However, I'm seeing a lot of for(;;) constructs on the web which are functionally equivalent to while(true)
What is the reasoning for this? Why would the infinite for loop be preferred over the infinite while loop?
// I even saw a java textbook that didn't use while loops at all! Leading to such monstrous constructs as:
String input = getInput();
for( ; !inputIsValid(input) ; )
{
//redo;
}

whileandforhere and the question wouldn't change.while(true)andfor(;;)mean the same thing. You obviously have a strong preference forwhile, others may have an equally strong preference forfor. It's impossible to say that one is more correct than the other. – Caleb Nov 10 '11 at 16:12for(;;)confusing at all. It's a standard C idiom, one which you'll documented in section 3.5 of K&R(2e). I understand that you don't like it; you should understand that others obviously prefer it (else you'd never see it). It may be more or less acceptable in languages other than C; you've tagged this language-agnostic which only decreases the possiblity of a definitive answer. Again, I voted to close because the Q isn't constructive; if I were offended I would have flagged as offensive instead of or in addition to closing. That is all. – Caleb Nov 10 '11 at 16:55wheeeeeeee { ... }– detly Nov 11 '11 at 1:40