• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

For /while loop confirmation

 
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
 
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.
 
Ranch Hand
Posts: 1067
2
IntelliJ IDE Spring Java
  • 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.
 
A wop bop a lu bob a womp bam boom. Tutti frutti ad:
Enterprise-grade Excel API for Java
https://products.aspose.com/cells/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!