Out of While and do-while , which is more efficient?
We often think that all the loops are same because we can use them almost everywhere and wherever we like in the Program but to become an efficient programmer we need to think where to use which loop so that our Programming can become efficient(More useful).
Explanation:
We know the while loop first test the condition then executes the Statements, and do-while first executes the statement then checks the test condition. So any Programmer would like to have control on it's program from the very start, so the while loop is more efficient.
Another way of thinking this would be using the do-while loop because it will run at-least on time to show the first statement(Even when the condition is wrong), So user will get atleast some Output. While on the other hand the while loop will not show anything.
No comments:
Post a Comment