这段代码中的while循环有什么作用?
while循环如何工作?
let numApples = Math.random() * 10;
while (numApples > 0) {
console.log("Giving away an apple");
numApples = numApples - 1;
}
console.log("No apples remaining!");
答案 0 :(得分:0)
基本上以伪代码执行以下操作。
initiate variable called numApples with a random number 0 - 10.
Then while that number is greater than zero,
Output a message to the console saying "Giving away an apple" then
Subtract one from the numApples number.
Finally when the numApples becomes equal to zero
Output a message to the console saying "No apples remaining!"