do-while 循环的目的是什么? [英] What is the purpose of a do-while loop?

查看:33
本文介绍了do-while 循环的目的是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道 do 是做什么的,以及它如何与 while 循环配合,但是 while 循环代码会不会相同,无论 do 是否存在?

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() 然后检查 condition!要使用 while 循环执行此操作,您必须编写:

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();
}

这篇关于do-while 循环的目的是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆