aspose file tools*
The moose likes Java in General and the fly likes Loops in java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Loops in java" Watch "Loops in java" New topic
Author

Loops in java

Scott Schollmeyer
Greenhorn

Joined: Apr 18, 2007
Posts: 14
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

Joined: Apr 20, 2002
Posts: 510
I have never heard of this problem. Would you please post the code the will not count past 5999?

Thank you
Scott Schollmeyer
Greenhorn

Joined: Apr 18, 2007
Posts: 14
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

Joined: Apr 18, 2007
Posts: 14
sorry about typo error
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3739
    
  16
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.


Joanne
Scott Schollmeyer
Greenhorn

Joined: Apr 18, 2007
Posts: 14
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

Joined: Apr 18, 2007
Posts: 14
I did forget to add "c++;+ before the end of the loop
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

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?


[Jess in Action][AskingGoodQuestions]
Scott Schollmeyer
Greenhorn

Joined: Apr 18, 2007
Posts: 14
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

Joined: Jan 30, 2000
Posts: 18671
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".


"I'm not back." - Bill Harding, Twister
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3739
    
  16
Or more generally
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
Your code shows a try block with no catch or finally - it won't even compile. Please show code that compiles.
Scott Schollmeyer
Greenhorn

Joined: Apr 18, 2007
Posts: 14
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

Joined: Sep 19, 2007
Posts: 29
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

Joined: Apr 18, 2007
Posts: 14
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

Joined: Apr 18, 2007
Posts: 14
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

Joined: Jan 30, 2000
Posts: 18671
[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

Joined: Apr 18, 2007
Posts: 14
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Loops in java