-
Some Guy
[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.
-
Run for your life!
"!" is the actionscript symbol for an inequality
So if you have " a != b" it would mean that a is not equal to b
-
"!this.init" means this.init does not resolve to true.
So it is saying...
if(this.init != true)
-
Some Guy
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.
-
Senior Member
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
-
Some Guy
thanks friends.
Excellent responses all around, nice explanations.
-
!(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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|