Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

loop problem

Avatar

Avatar
Validate 10
Level 2
eugzl
Level 2

Likes

5 likes

Total Posts

171 posts

Correct Reply

5 solutions
Top badges earned
Validate 10
Validate 1
Ignite 5
Ignite 3
Ignite 1
View profile

Avatar
Validate 10
Level 2
eugzl
Level 2

Likes

5 likes

Total Posts

171 posts

Correct Reply

5 solutions
Top badges earned
Validate 10
Validate 1
Ignite 5
Ignite 3
Ignite 1
View profile
eugzl
Level 2

17-04-2018

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.

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Boost 50
MVP
_Bruce_Robertson
MVP

Likes

270 likes

Total Posts

1,782 posts

Correct Reply

372 solutions
Top badges earned
Boost 50
Boost 5
Boost 3
Boost 250
Boost 25
View profile

Avatar
Boost 50
MVP
_Bruce_Robertson
MVP

Likes

270 likes

Total Posts

1,782 posts

Correct Reply

372 solutions
Top badges earned
Boost 50
Boost 5
Boost 3
Boost 250
Boost 25
View profile
_Bruce_Robertson
MVP

17-04-2018

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

Answers (0)