Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/436.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 而循环仍在触发时不应该太多_Javascript_While Loop - Fatal编程技术网

Javascript 而循环仍在触发时不应该太多

Javascript 而循环仍在触发时不应该太多,javascript,while-loop,Javascript,While Loop,在JavaScript中执行while循环,但当usernum

在JavaScript中执行while循环,但当usernum<50时显示120,但当usernum为60时计算

var userNum=4;//将使用值4、10和60测试代码
/*你的解决方案在这里*/
做{
userNum=2*userNum;
log(userNum);
}

而(userNum<50)Ado while循环运行代码一次,然后测试条件,如果条件为false,则停止执行。您应该使用whilefor循环

while(userNum < 50){
userNum = 2 * userNum;
console.log(userNum);
}
while(userNum<50){
userNum=2*userNum;
log(userNum);
}
同时检查条件,如果为真,则运行代码,否则停止

如果运行代码为真,则检查条件(基本上是while的较短版本)


执行时运行循环,检查条件,如果为真,则再次运行或退出

Ado while循环运行代码一次,然后测试条件,如果为false,则停止执行。您应该使用whilefor循环

while(userNum < 50){
userNum = 2 * userNum;
console.log(userNum);
}
while(userNum<50){
userNum=2*userNum;
log(userNum);
}
同时检查条件,如果为真,则运行代码,否则停止

如果运行代码为真,则检查条件(基本上是while的较短版本)


执行时运行循环,检查条件,如果为真,则再次运行或退出

while
do while
不同
while
do while
不同。你明白了。。很好,你明白了。。美好的