This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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 Android Security Essentials Live Lessons this week in the Android 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:
subject: Problem with nested loop
Similar Threads
problem with errorPage and isErrorPage="true"
colums Need help!!
Inserting form data into database?
private constructor inSuper Class?