PDA

View Full Version : if statement



regbolD
July 9th, 2009, 11:39 AM
can I write this?


if(!(!vidPlaying && !vidPaused)){

}
and is this going to say: if both of them are not false?

or I am tripping? :D

IQAndreas
July 9th, 2009, 11:57 AM
I get those days. You have to many exclamation points. This will be enough.

if((!vidPlaying) && (!vidPaused)) {

}

m90
July 9th, 2009, 12:54 PM
Um, if both of them are supposed to be not false, why don't you just check if both of them are true?



if (vidPlaying && vidPaused){
}


But maybe I got you wrong here?

regbolD
July 9th, 2009, 06:19 PM
I get those days. You have to many exclamation points. This will be enough.
ActionScript Code:

if((!vidPlaying) && (!vidPaused)) {

}




you have confused me both :D

isnt this what you are saying the same as this?


if(!vidPlaying && !vidPaused) {

}

which means if both are false?

what I need is if both are NOT false, so if either one of them is true or both are true , this is not accepted.

so I think the statement I wrote first is correct, but maybe I am wrong :D

JonnyR
July 9th, 2009, 09:34 PM
RegbolD,

I think you are looking for the OR (||) operatior?



// If vid is not playing OR if vid is not paused.
if (!vidPlaying || !vidPause)
{
invokeMagic();
}


Jonny.

xgraves
July 9th, 2009, 11:01 PM
Right, duh. I deleted my last post b/c i was totally confused. But I still don't fully understand this:
"what I need is if both are NOT false, so if either one of them is true or both are true , this is not accepted."

I think the reason this is such a mental pretzel is because
A) it has so many negatives.
B) it makes a difference if you need them both to be the same, or just need to check one.
C) vidPlaying and vidPause are opposite concepts, so it's weird to check if they're equal.

I think it will help a lot if you can tell us what you're going to do once the condition is met.

For instance, assuming vidPlaying and vidPaused are Booleans that are set by something like VideoEvent.STATE_CHANGE, we can:



// check if video is paused for any reason:
if (!vidPlaying || vidPaused) {
// video is not playing
}

// check if video is playing and unpaused:
if (vidPlaying && !vidPaused) {
// video is playing and specifically not paused
}

// check if video is not playing and pause is true:
if (!vidPlaying && vidPaused) {
// video is paused and pause flag is set
}

etc...
PS, i still think it's a good idea to distinguish whether you truly mean "false" in the Boolean sense or just "exist" in the mathematical sense, and be precise about the variable casting and checking. For instance, !vidPlaying could mean vidPlaying=false, vidPlaying=0 or vidPlaying=null.

regbolD
July 10th, 2009, 05:40 AM
"what I need is if both are NOT false, so if either one of them is true or both are true , this is not accepted." (http://www.kirupa.com/forum/member.php?u=52486)
I wrote it wrote above, it should be the other way around :D


if(!(!vidPlaying && !vidPaused)){

}forget about meaning of these two, and if you want to know when these 2 are false -> its in the stop state.

anyway, I want in a case of:

false true
true false
true true

accept this!

in a case of:

false false

dont accept this!

thats why I wanted :D

regbolD
July 10th, 2009, 05:47 AM
http://img167.imageshack.us/img167/9299/homerdoh.jpg (http://img167.imageshack.us/i/homerdoh.jpg/)

IQAndreas
July 10th, 2009, 11:39 AM
if (vidPlaying || vidPaused)
{

}

xgraves
July 10th, 2009, 08:43 PM
anyway, I want in a case of:

false true
true false
true true

accept this!

in a case of:

false false

dont accept this!


Ok, so you're saying accept this under any circumstance except if both are false. So this is what you want:


if (!vidPlaying && !vidPause) {
// do not accept this
} else {
// accept this
}

Now I see why you were asking about !(!a && !b), it's the inverted version of the same logic.