Skip to main content
Participating Frequently
August 16, 2013
Answered

Checking Multiple Similar Or's in an if statement. [AS2]

  • August 16, 2013
  • 2 replies
  • 664 views

Hello, I know this is probably a very obvious question, but I'm new to flash.

Can I do something like,

if (jellyfish == 3, 74, 95, || 1006) {

//Do Stuff

}

Or would I have to do:

if (jellyfish == 3 || jellyfish == 74 || jellyfish == 95 || jellyfish == 1006) {

//Do Stuff

}

Let me know if there is something closer to the first one, or if I'm going to have to have pages within one if statement.

Thanks,

Christopher

This topic has been closed for replies.
Correct answer kglad

you must do the latter, but if it's worthwhile you can use a for-loop:

var a:Array=[3,74,95,1006];

for(var i:Number=0;i<a.length;i++){

if(jellyfish==a){

//do stuff

break;

}

}

2 replies

Ned Murphy
Legend
August 16, 2013

The second is the correct way to specify multiple conditions

Participating Frequently
August 16, 2013

I know it is correct, but I was wondering if there was a simpler way.

Thanks for the help, though.

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
August 16, 2013

you must do the latter, but if it's worthwhile you can use a for-loop:

var a:Array=[3,74,95,1006];

for(var i:Number=0;i<a.length;i++){

if(jellyfish==a){

//do stuff

break;

}

}

Participating Frequently
August 16, 2013

Thank you so much!
This is exactly what I needed!

You were missing a parenthisis, but besides for that, it works beautifully and looks a lot more visually appealing!

kglad
Community Expert
Community Expert
August 16, 2013

you're welcome.

(and i corrected that paranthesis in case someone else copies that code.)