• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

For loop error?

 
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
reply
    Bookmark Topic Watch Topic
  • New Topic