What is the purpose of a do-while loop?
问题 I know what do does, and how it cooperates with the while loop, but won't a while loop code be the same, whether or not the do is there? 回答1: Consider the following: while(condition){ myFunction(); } and do{ myFunction(); }while(condition); The second form executes myFunction() at least once then checks the condition ! To do so with a while loop you've to write: myFunction(); while(condition){ myFunction(); } 回答2: Use do-while() construct when you have to get your task executed at least once