While loop with Or statement

Avatar

09-06-2008

Is it possible to have a while loop with the or (||) comparison.



I've been trying while (x != 1 || 2) and variations such as while (x != 1 || x != 2).



When I have just one statement the loop performs as normally, but when I add the second argument it seems to become an infinite loop, I've tested to make sure the variable is updating so I'm pretty sure the problem lies in my loop statement.



I am fairly new to javascript so this might be a case of me trying to use features from other languages that arent available in javascript.



Thank you



Paul

Replies

Avatar

Avatar
Coach
Level 10
Jasmin_Charbonn
Level 10

Likes

149 likes

Total Posts

2,154 posts

Correct reply

97 solutions
Top badges earned
Coach
Give Back 1000
Give back 900
Give Back 800
Give back 600
View profile

Avatar
Coach
Level 10
Jasmin_Charbonn
Level 10

Likes

149 likes

Total Posts

2,154 posts

Correct reply

97 solutions
Top badges earned
Coach
Give Back 1000
Give back 900
Give Back 800
Give back 600
View profile
Jasmin_Charbonn
Level 10

10-06-2008

Where are you putting this java code? In the script service, in a custom component or you are adding conditions on a route coming out of an activity?



Jasmin

Avatar

10-06-2008

The code is being used as data validation coming from app.response triggered when a button is pressed. I apologize i think i posted this question in the wrong forum.

Avatar

10-06-2008

Hi Paul,



(x != 1 || x != 2) will always evaluate to true. Thus your loop will run forever.



I guess what you wanted was: (x != 1 && x != 2)



Khoa Tran

avoka.com