10-while循环
3.5.1 while循环
在JavaScript中,最基本的循环是while循环,它检查一个表达式,只要该表达式为true就执行大括号({})的代码,直到该表达式为false为止。
例如,下面的while循环将不断执行,直到i的值为5:
var i = 1;
while (i<5){
print("Iteration " + i + "\n");
i++;
}
上述代码的输出如下:
Iteration 1
Iteration 2
Iteration 3
Iteration 4