Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Loops in java

 
Scott Schollmeyer
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there any loops in java that can count over 6000. Ihave tried while and for loop and they doth stop at 5999 I need one that at least can count over 9000. thanks
 
Michael Ku
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have never heard of this problem. Would you please post the code the will not count past 5999?

Thank you
 
Scott Schollmeyer
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you make a regular for loop this will not run. I am actul triing to read the size of an array that keeps growing as info is adding and the array will it large right now it size is 8169 and I need a loop to be able to read each cell one at a time.
 
Scott Schollmeyer
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry about typo error
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What happens when you try to run that code with a value bigger than 6000 ? There should be no problem with 8169. I suspect the problem is elsewhere in your code.
You refer to an array that keeps growing. The size of an array cannot be changed once it is created.
Post some more of your code - particularly the bit that you think is changing the size of the array - and maybe we can spot where the error is really happening.
 
Scott Schollmeyer
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
O.k. you asked for it I will try to boil it down to simpleest I can.

now you would have to build t text file that would put more then 6000 item into the array and trust me when i say you can i have done it. put when I go to pull them out the while loop stops at 5999. I have ram a "System.out.println" for the value of ca and it alway ends at 5999.
 
Scott Schollmeyer
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did forget to add "c++;+ before the end of the loop
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's nothing about this program that would make it stop at 5999 lines.

It's possible that the program runs out of memory and aborts with an "OutOfMemoryError" at some point, but that would happen before you get to the second "while" loop. The lines in the file would have to be quite long for this to happen.

When it stops, is there any kind of message or diagnostic? Can you cut and paste the (end of the) output for us? What can you tell us about the input file?
 
Scott Schollmeyer
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No it does not stop I found out thtit was ending the loopat 5999 is I put "system.out.println +ca);" in the loop and it stop at 5999 and then went on to run the rst of the program. so the program runs fine no memory errors or problems running it just does not go above 5999 and the array size is 8169. I know this because I put "System.out.println("what is array size: " + filearray.size());" before the while loop.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I understand the problem correctly: the reason the loop stops at 5999 is because the loop condition is "a < 6000", and 5999 is the largest number that is less than 6000. If you want the loop to include 6000 as well, then the loop condition should be either "a <= 6000" or "a < 6001".
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or more generally
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your code shows a try block with no catch or finally - it won't even compile. Please show code that compiles.
 
Scott Schollmeyer
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jim Yingst:
If I understand the problem correctly: the reason the loop stops at 5999 is because the loop condition is "a < 6000", and 5999 is the largest number that is less than 6000. If you want the loop to include 6000 as well, then the loop condition should be either "a <= 6000" or "a < 6001".


the actul code is an array that is over 6000 cells large but it will not run when I do it
 
Mladen Grabowsky
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My guess is,

that your IDE can only display 6000 lines on the output console and you're not seeing any more output so you're assuming that your program stopped.

Try running your prog on the console.

There is no such thing as limitations on the number of iterations in any kind of loops in java. Just try too make an infinite loop
[ October 08, 2007: Message edited by: Mladen Girazovski ]
 
Scott Schollmeyer
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jim Yingst:
Your code shows a try block with no catch or finally - it won't even compile. Please show code that compiles.
I forgot the "ca++; before the end of the while loop if you add that it will run but you need to creat your own text file for it to read from
 
Scott Schollmeyer
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Mladen Girazovski:
My guess is,

that your IDE can only display 6000 lines on the output console and you're not seeing any more output so you're assuming that your program stopped.

Try running your prog on the console.

There is no such thing as limitations on the number of iterations in any kind of loops in java. Just try too make an infinite loop

[ October 08, 2007: Message edited by: Mladen Girazovski ]
I thought the same thing so I created a nest loop and it went through and every time it hit this loop it only went 5999 and then down to the next code then into this loop and ran 5999 and I raan the loop 8 or 10 time it will never count above 5999.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[Jim]: Your code shows a try block with no catch or finally - it won't even compile. Please show code that compiles.

[Scott]: I forgot the "ca++; before the end of the while loop if you add that it will run but you need to creat your own text file for it to read from


That has nothing to do with what I'm asking. Your code needs some form of error handling, and what you've shown there will not work at all. One possibility is that there really is an error occurring in your code, but you're hiding it with poor error handling. That's why I want to see what you're actually doing with the error handling. This may sound like a silly error to be asking about, but the simple fact is that Java arrays can easily handle more than 8000 elements, and Java loops can easily loop through all of them. If you're having trouble with this, there's a silly error somewhere, and we won't find it if you can't show us the code you're actually using.
 
Scott Schollmeyer
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jim Yingst:
[Jim]: Your code shows a try block with no catch or finally - it won't even compile. Please show code that compiles.

[Scott]: I forgot the "ca++; before the end of the while loop if you add that it will run but you need to creat your own text file for it to read from


That has nothing to do with what I'm asking. Your code needs some form of error handling, and what you've shown there will not work at all. One possibility is that there really is an error occurring in your code, but you're hiding it with poor error handling. That's why I want to see what you're actually doing with the error handling. This may sound like a silly error to be asking about, but the simple fact is that Java arrays can easily handle more than 8000 elements, and Java loops can easily loop through all of them. If you're having trouble with this, there's a silly error somewhere, and we won't find it if you can't show us the code you're actually using.

your correct I forgot the catch with the try
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic