wood burning stoves 2.0
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

For /while loop confirmation

Asma Hafeez

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.
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: 986

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
It's not a secret anymore!