• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

For /while loop confirmation

 
Asma Hafeez
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 158
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
William Barnes
Ranch Hand
Posts: 986
Eclipse IDE Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks.
I have never seen so many people go on about the speed of different loops. Your answer is the correct response.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic