aspose file tools*
The moose likes Beginning Java and the fly likes Problem with nested loop Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Problem with nested loop" Watch "Problem with nested loop" New topic
Author

Problem with nested loop

Clay Bartlett
Greenhorn

Joined: Nov 28, 2004
Posts: 4
for(int i=0;i<=3;i++)
for(int i=1;i<=4;i++)
{
System.out.println(i);
}

I must be blind but I dont see the problem with this
Logan Owen
Greenhorn

Joined: Dec 01, 2004
Posts: 24
1) you are missing the closing bracket
2) you need a diff iterator (not i) for inner loop, because you are setting i back to 1 every time, which will never let the outer loop get to 3, so the loop will go on infinitly.

Possible code:
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
I suspect that this doesn't even compile, am I correct? The reason is that the computer thinks you are declaring the same variable (i) twice, as Logain said. So you need to change the variable used in the inner loop. Typically j is used in such situations.

HTH

Layne


Java API Documentation
The Java Tutorial
Clay Bartlett
Greenhorn

Joined: Nov 28, 2004
Posts: 4
Thanks this might be the answer I'll post something later to let you know whether it solves the problem
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem with nested loop