my dog learned polymorphism*
The moose likes Beginning Java and the fly likes For loop error? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "For loop error?" Watch "For loop error?" New topic
Author

For loop error?

Naf Rash
Ranch Hand

Joined: Feb 19, 2004
Posts: 85
I have the following code but it never gets to

i have checked the values for variables and they all seem to be correct. The method getMatrix is defined in another class but I'm still having having problems. I've tried going through the for loops myself and can't see anything wrong with them. Can you understand why?


[ EJFH Edited formatting]
[ March 10, 2004: Message edited by: Ernest Friedman-Hill ]
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

I've reformatted your code so that the indentation shows the structure. It looks like you're editing code in some sort of editor that doesn't do this for you automatically -- you really should consider using a better editor or IDE; a real programmer's editor is a huge help. An automated formatter can instantly show you problems (like the problem here!) with your code.
In any case, with the indentation above, it's easy to see that the small loops over "i" and "all" near the bottom of the page are actually inside the large loops over "i" and "all" that start near the top of the routine. In all the time I've been programming and teaching, I've never actually seen anyone make this particular error, so congratulations
The inner loops are making changes to the loop counters being used by the outer loops. Therefore, depending on the values of the various constants, the outer loops will be executed either fewer or more times than you'd expect. Since you're saying it never gets to the bottom of the routine, I suspect that row1 is less than theRowCount, so that the variable "all" never gets large enough to finish that large inner for loop!
Anyway, I have no idea what the logic of this routine is supposed to be, but hopefully you'll be able to sort it out.


[Jess in Action][AskingGoodQuestions]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: For loop error?
 
Similar Threads
Arrays -HELP!!!!!!!
Syntax error- HELP
Method - HELP!
Errors - can't understand why. HELP!!!
Referring to an array-HELP!