The Original way of a for loop you may have in you mind:
for(initialization; condition; inc/dec/divide..)
And what you mentioned: for (initialization; Inc & check; nothing)
What does it mean? : for(some blaBla; any Bla; some, more, bla)
You may have any expression any where. The Original version is just a convention we follow. Go ahead an write a printing statement or a bitwise operator instead of some blaBla
try it out!
Update:
Why :
for (int x = 1; x++ < 10;)
{
System.out.println(x);
}
Prints 2..10? For the answer first try to execute :
for (int x = 1; ++x < 10;)
{
System.out.println(x);
}
It prints from 2..9
You should understand how pre/post fix operators work. x++
in the loop increments the value but not immediately. It increments after x++ < 10;
Where as ++x < 10;
first increments and then rest everything happens.
So, when the x value is 9, 9(++)< 10 -> 9 is less ? yeah, now 9++ occurs.It then increments x. but ++x increments 1st so ++9< 10 -> 10<10 NO.