私が読んでいる本の例から、次のコードをすべて理解しています。コメント行を除いて。それなしではループは決して終わらないと思いますか?しかし、その背後にある論理はわかりません。
var drink = "Energy drink";
var lyrics = "";
var cans = "99";
while (cans > 0) {
lyrics = lyrics + cans + " cans of " + drink + " on the wall <br>";
lyrics = lyrics + cans + " cans of " + drink + " on the wall <br>";
lyrics = lyrics + "Take one down, pass it around, <br>";
if (cans > 1) {
lyrics = lyrics + (cans-1) + " cans of" + drink + " on the wall <br>";
}
else {
lyrics = lyrics + "No more cans of" + drink + " on the wall<br>";
}
cans = cans - 1; // <-- This line I don't understand
}
document.write(lyrics);