1

我不知道为什么我else if的不工作!

 var workSurvival:Number = 0;
    var work:int = parseInt(work_txt.text);

if(work < 60 > 0){
    workSurvival = work*12;
        trace("work 1-" + workSurvival);
}else if(work < 120 > 60){
    workSurvival = work*25;
        trace("work 2-" + workSurvival);
        trace(work);
}else if(work == 120){
    bestScore -= 1;
        trace("Good Score!");
}else if(work < 200 > 120){
    workSurvival = work*8;
        trace("work 3-" + workSurvival);
}else if(work < 401 > 200){
    workSurvival = work*4;
        trace("work 4-" + workSurvival);
}
4

3 回答 3

5

if(work < 60 > 0)不是有效的 IF 语句。您需要将其重写为

if(work > 0 && work < 60)

这里的所有其他声明也是如此。

于 2013-10-15T23:08:37.167 回答
0

Expanding on what howrad said: work < x > y is equivalent to (work < x) > y, so during evaluation it will end up as true > y or false < y (after work < x is evaluated) and not exhibit the desired range behavior ..

Now, how I would write it:

if(work < 60){
}else if(work < 120){
}else if(work == 120){
}else if(work < 200){
}else if(work < 401){
}else{
}

That is, "inch along": this works because the conditionals go from specific to general across the range and the first matching conditional will terminate the sequence of checks.

于 2013-10-15T23:12:59.997 回答
0

if 语句中的条件不正确

将它们更改为

if(work>0&&work<60)代替if(work < 60 > 0)

else if(work>60&&work<120)代替else if(work < 120 > 60)

else if(work>120&&work<200)代替else if(work < 200 > 120)

if(work>200&&work<401)代替else if(work < 401 > 200)

你的代码应该可以正常工作

于 2013-10-16T03:43:44.700 回答