-
!=true == false? :)
maybe a stupid question, but i will still ask :P
if i have a boolean and if i say if (something != true), is this the same as saying if (something == false) ?
at first i thought yes, but i am not so sure anymore
Last edited by regbolD; 01-18-2009 at 05:59 PM.
-
Conditionals will break everything into boolean values so:
PHP Code:
// these are all true statements
true == true
false == false
true != false
// these are all false statements
true == false
true != true
false != false
So yes - saying something "is not True" is the same as saying it "is false"
-
Intermediate Game Dev
Not exactly. Here's an example:
PHP Code:
varA = "true" varB = "b"
if (varA == true) { trace(varA); //returns "true" } if (varB != true) { trace(varB); //returns "b", becacuse even though it is not true and not false, //the statement is still correct, because "b" IS NOT true }
Needs an update...
-
Those are both strings - which get evaluated to 'true' if they have ANY value in them - Flash doesn't care what that value is...
PHP Code:
var s:String = "false";
var b:Boolean = Boolean(s);
trace(s, b); // false true
-
so if i dont even declare something as boolean and just say in my code somewhere that: something = true;
an then later ask:
if (something != true)
is the same as saying?
if (something == false)
so basically does this mean that whenever i just mention true or false boolean is implied?
Last edited by regbolD; 01-19-2009 at 08:49 AM.
-
Whenever you use if (or any other conditional operator) everything will get cast to Boolean - so in your example (assuming 'something' is in the same scope as your if statement) that should work fine. You can even do away with the comparison altogether:
if(something){}
if(!something){}
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
|