-
Multiple "if" conditions
Hi everyone,
Is it possible to compare an if statement to multiple conditions? The Actionscript I have in place is:
Code:
myVar = 4;
if(myVar == 1 || 2 || 3){
trace("Test 1");
}
else{
trace("Test 2");
}
When I run this Actionscript, it traces "Test 1", rather than "Test 2" as I would expect. Does anyone know the proper syntax for what I'm trying to accomplish? Because of the specifics of the project, I can't do multiple if else statements, I need to compare multiple values in the first if statement.
Any help is appreciated!
Luke
Last edited by Outshine; 03-09-2007 at 03:50 PM.
-
Of course, immediately after posting I figure out the correct syntax. It is:
Code:
myVar = 4;
if((myVar == 1) || (myVar == 2) || (myVar == 3)){
trace("Test 1");
}
else{
trace("Test 2");
}
-
You could also use a switch statement:
code:
myVar=4;
switch(myVar){
case 1:
case 2:
case 3:
trace("Test 1");
break
default:
trace("Test 2");
break;
}
K.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|