A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: [help] What does ! in front of an if condition represent?

  1. #1
    Some Guy KGKraeer's Avatar
    Join Date
    May 2000
    Location
    Los Angeles
    Posts
    133

    [help] What does ! in front of an if condition represent?

    for example:

    if(!this.init) {
    this.vx = -1 * Math.cos(init_angle_radian) * this.speed;
    this.vy = -1 * Math.sin(init_angle_radian) * this.speed;
    this.init = true;
    }

    Kind of a noob question, been seeing it in the examples I'm studying.

  2. #2
    Run for your life! Phlook's Avatar
    Join Date
    Jul 2003
    Location
    Vancouver, Canada
    Posts
    679
    "!" is the actionscript symbol for an inequality

    So if you have " a != b" it would mean that a is not equal to b

  3. #3
    Member
    Join Date
    Mar 2000
    Location
    Atlanta
    Posts
    83
    "!this.init" means this.init does not resolve to true.

    So it is saying...
    if(this.init != true)

  4. #4
    Some Guy KGKraeer's Avatar
    Join Date
    May 2000
    Location
    Los Angeles
    Posts
    133
    ah, cool. I knew it had to have a similar meaning to a!= b (a does not equal b)....I'd never seen it in an if condition before, especially without an "=" sign right after it.

    Thanks man.

  5. #5
    Senior Member sand858's Avatar
    Join Date
    Aug 2001
    Posts
    327
    Officially "!" is the not symbol, meaning the negation of the following expression.

    !(expr) is true if expr == false or false if expr == true

    or

    !(true) is equivalent to false
    !(false) is equivalent to true

  6. #6
    Some Guy KGKraeer's Avatar
    Join Date
    May 2000
    Location
    Los Angeles
    Posts
    133
    thanks friends.

    Excellent responses all around, nice explanations.

  7. #7
    Member
    Join Date
    Mar 2000
    Location
    Atlanta
    Posts
    83
    !(true) is equivalent to false
    This is not always the case. For example.

    Code:
    var s:Boolean;
    
    if(!s){
    trace("NOPE!");
    trace(s);
    }
    This will trace. 's' is not false, it's undefined.

    I often use ! to weed out undefined variables.

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