【发布时间】:2016-09-17 08:26:41
【问题描述】:
我想知道 JavaScript 中 continue 语句的结构化等价物是什么?我试图摆脱 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];
};
}
【问题讨论】:
-
为什么需要改变?
continue是语言的一部分,非常适合您的需求。
标签: javascript