Expand my Community achievements bar.

SOLVED

loop problem

Avatar

Level 5

I would like to create loop to check data entered by user into TextField with all array values in global variable. I tried like this:

var i = 0; 

for (i = 0; i < 3; i++) { 

     if (txtName.rawValue == _Name[i]) { 

          xfa.host.messageBox("Your NAME is correct."); 

     } 

if (i == 3) { 

     xfa.host.messageBox("Your NAME is wrong."); 

where:

      _Name = eval(Names.value) is global variable array value

and

    txtName is TextField where user type data.

When I run the execute that code I got the second message pop up first and then first message . How to fix the problem?

Thanks.

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi,

I think you just need a break statement after "Your NAME is correct" message, this will stop the loop and so at the end of the value of I will never be 3.

so;

for (i = 0; i < 3; i++) {  

     if (txtName.rawValue == _Name[i]) {  

          xfa.host.messageBox("Your NAME is correct.");  

          break;

     }  

}

Bruce

View solution in original post

1 Reply

Avatar

Correct answer by
Level 10

Hi,

I think you just need a break statement after "Your NAME is correct" message, this will stop the loop and so at the end of the value of I will never be 3.

so;

for (i = 0; i < 3; i++) {  

     if (txtName.rawValue == _Name[i]) {  

          xfa.host.messageBox("Your NAME is correct.");  

          break;

     }  

}

Bruce