This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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
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>