File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes  For /while loop confirmation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark " For /while loop confirmation" Watch " For /while loop confirmation" New topic
Author

For /while loop confirmation

Asma Hafeez
Greenhorn

Joined: Oct 19, 2001
Posts: 3
Hi all,
Thanx for discussion about For & While Loop. I think abt it that both are same loops(Am i right) no one is faster. It depeneds on compiler or program,how we use these loops in a program.
Pls. tell me if i m right.I will be very thankfull.
Thanx,
Asma
Michael Bruesch
Ranch Hand

Joined: Sep 23, 2001
Posts: 158
Don't try to think about which loop is faster, for, while, or do-while. Try to think about which loop is most appropriate for a particular situation. When you know exactly how many iterations you must go through, use the for loop. If the loop has an unknown amount of iterations, and may possibly not be executed at all, use the while loop, it's a zero or more iteration loop. When you know you need to execute a piece of code first, then check for a certain condition and possibly execute that piece of code again, use the do-while loop, it's a one or more iteration loop. I honestly don't know which loop would be "faster", but I bet if you use the method I described above to determine which loop to use, you'll always pick the "correct" loop, and probably the fastest.


Michael J Bruesch<br /><i>I code, therefore I am.</i>
William Barnes
Ranch Hand

Joined: Mar 16, 2001
Posts: 984

Thanks.
I have never seen so many people go on about the speed of different loops. Your answer is the correct response.


Please ignore post, I have no idea what I am talking about.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: For /while loop confirmation
 
Similar Threads
Delaying Execution
Threading issue
JavaBat Array Problem (larger value w/o loop)
Using FOR loop to loop in a resultset
loops in ant script