jQuery in Action, 3rd edition
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

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Problem with nested loop" Watch "Problem with nested loop" New topic

Problem with nested loop

Clay Bartlett

Joined: Nov 28, 2004
Posts: 4
for(int i=0;i<=3;i++)
for(int i=1;i<=4;i++)

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

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.



Java API Documentation
The Java Tutorial
Clay Bartlett

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
It's not a secret anymore!