javascript VBscript中Do while/Do until的区别
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14151778/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Difference of Do while/Do until in VBscript
提问by Guffa
What is the difference between Do whileand Do untilloops in vbscript, and what are the equivalent loops statements in javascript?
vbscript 中的Do while和Do until循环有什么区别,javascript中的等效循环语句是什么?
回答by Guffa
The only difference between do while
and do until
is that the first one loops as long as the condition is true, while the second one loops as long as the condition is false.
do while
和之间的唯一区别do until
是,只要条件为真,第一个就会循环,而只要条件为假,第二个就会循环。
In Javascript you use do {} while()
or while() {}
. Example:
在 Javascript 中,您使用do {} while()
或while() {}
。例子:
var cnt = 0;
do {
cnt++;
} while (cnt < 10);
and:
和:
var cnt = 0;
while (cnt < 10) {
cnt++;
}
Use the !
operator to negate the condition to get the same functionality as until
.
使用!
运算符否定条件以获得与 相同的功能until
。
回答by Madura Harshana
Do while, (Repeat Code While a Condition is True)
Do while,(在条件为真时重复代码)
Do While i>10
some code
Loop
or
或者
Do
some code
Loop While i>10
Do until, (Repeat Code Until a Condition Becomes True)
直到,(重复代码直到条件变为真)
Do Until i=10
some code
Loop
or
或者
Do
some code
Loop Until i=10
javascripts,
javascripts,
while ( i>10)
{
some code
}
or,
或者,
do
{
some code
} while (i>10);
Hope you got the idea
希望你有想法
回答by Mr. Polywhirl
Google is your friend. The do-while
loop executes 1 or moretimes, while a while
loop executes 0 or moretimes.
谷歌是你的朋友。的do-while
循环执行1个或更多倍,而一个while
循环执行0以上次。
From MSDN:
来自 MSDN:
While Required unless Until is used. Repeat the loop until condition is False.
Until Required unless While is used. Repeat the loop until condition is True.