-
For loop
I was doing some search on for loops and i bumped on this tiny code which is confusing to understand. below is the code
class Ex
{
public static void main(String[] args)
{
int i;
for(i=0, System.out.println(i); ; i++)
{
}
}
}
Now the above code runs fine. But when i declare the entire variable in inside the for loop like "for(int i=0, System.out.println(i); ; i++)" it throws error " ; expected" .
Now can any kindly explain me the difference?
Thank you
-
Re: For loop
Read paragraph 14.14.1. in the JLS: the for-initialization part can either be a local variable list declaration or a list of expression statements; they can't be combined.
kind regards,
Jos
-
Re: For loop