我想知道JavaScript中的continue语句的结构化等价物是什么?我试图摆脱继续的声明,但不知道如何。任何人都可以将我指向正确的方向吗?谢谢!JavaScript中continue语句的等效代码
function Hand() {
this.cards = new Array();
this.addOneCard = function(card) {
this.cards.push(card);
}
this.evaluateHand = function(){
// Needs to handle two aces better
var total1 = new Number;
var total2 = new Number;
for(var i in this.cards) {
if (this.cards[i].value == "A") {
total1 += 1;
total2 += 11;
continue;
}
if (isNaN(this.cards[i].value * 1)) {
total1 += 10;
total2 += 10;
continue;
}
total1 += Number(this.cards[i].value);
total2 += Number(this.cards[i].value);
}
return [total1, total2];
};
}
你为什么需要改变? “继续”是语言的一部分,非常适合您的需求。 –