A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Multiple "if" conditions

  1. #1
    Senior Member
    Join Date
    Jan 2004
    Posts
    165

    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.

  2. #2
    Senior Member
    Join Date
    Jan 2004
    Posts
    165
    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");
    }

  3. #3
    FK Slacker
    Join Date
    Jun 2000
    Location
    vancouver
    Posts
    3,208
    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
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center