do-while循环的目的是什么?
问题描述:
我知道它做了什么,以及它如何与while循环合作,但是不会有一个while循环代码是相同的,无论是否存在?
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?
答
请考虑以下因素:
while(condition){
myFunction();
}
和
do{
myFunction();
}while(condition);
第二个表格执行 myFunction()
at至少一次检查条件
!要使用进行
循环,你要编写:
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();
}