条件和运营商的行为错误

时间:2012-02-26 19:42:29

标签: actionscript-3 operators conditional-statements

我进行了以下迭代:



    The content of the array respuesta is: Africa, Europa, Norteamerica
    The content of the array resultado is: Incorrect, Correct, Incorrect

    I created a Array to include both of them: 

    var contPre:Array = [ this.respuesta, this.resultado ];



    for (var a:uint = 0; a < contPre[0].length; a++){

     if (this.radioGroup1.selection.value == contPre[0][a] && 
          contPre[1][a] == "Correcto") {

        result_txt.text = "Correct";
        valor = 1;

      } else {

        result_txt.text = "Incorrect";
        valor = 0;

        }

      }


     The first time that I've executed this I found this:

     this.radioGroup1.selection.value   Obtained value: Europa
     contPre[0][a]:                     Obtained value: Europa 
     contPre[1][a]:                     Obtained value: Correcto

     The sentence go out for the second option "Incorrect".


     Somebody can explain why is this happening?


1 个答案:

答案 0 :(得分:0)

问题在于,当您找到正确的答案时,您不会从循环中断开。所以改变:

if (this.radioGroup1.selection.value == contPre[0][a] && contPre[1][a] == "Correcto") {
    result_txt.text = "Correct";
    valor = 1;
}

成:

if (this.radioGroup1.selection.value == contPre[0][a] && contPre[1][a] == "Correcto") {
    result_txt.text = "Correct";
    valor = 1;
    break; // Add this line
}