Results 1 to 3 of 3
Thread: For loop
- 04-01-2012, 01:36 PM #1
Member
- Join Date
- Jan 2012
- Posts
- 55
- Rep Power
- 0
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
- 04-01-2012, 01:53 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,412
- Blog Entries
- 7
- Rep Power
- 17
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,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 04-01-2012, 02:05 PM #3
Member
- Join Date
- Jan 2012
- Posts
- 55
- Rep Power
- 0
Similar Threads
-
Problem with while loop, assigning a variable with a different value every loop? Help
By JavaProg in forum New To JavaReplies: 2Last Post: 11-07-2011, 02:25 AM -
Is it Possible? Array elements Initialized in Loop, can it be viewed outside loop?
By JPH in forum New To JavaReplies: 1Last Post: 10-01-2011, 02:12 AM -
JTextField loop 2x for-loop WEIRD!
By Streetproject in forum AWT / SwingReplies: 2Last Post: 02-16-2011, 05:46 PM -
How can I rewrite the following while loop using a for loop?
By gt11990 in forum New To JavaReplies: 5Last Post: 04-30-2010, 05:05 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks