是
if(a)
{
do
{
b();
}
while(a);
}
一模一样
while(a)
{
b();
}
?
最佳答案
它们是相同的,我将提供一个示例,您可能实际上想要使用“Do-While”而不是 while 循环。
do{
x = superMathClass.performComplicatedCalculation(3.14);
}
while (x < 1000);
相对于
x = superMathClass.performComplicatedCalculation(3.14);
while ( x < 1000);
{
x = superMathClass.performComplicatedCalculation(3.14);
}
使用 Do-While 的参数如上所示。假设行 x = superMathClass.performComplicatedCalculation(3.14);
不仅仅是一行代码,而是 25 行代码。如果您需要更改它,请在 do while 中只更改一次。在 while 循环中,您必须更改它两次。
我确实同意,你应该避开它们,但也有支持它们的论点。
关于javascript - if(){do{};while();} 和 while{} 完全一样吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11102374/