2012-02-26 94 views
0

错误的行为我有以下迭代:与条件和运营商

 


    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? 


回答

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 
}