Forgot username/password? Don't have an account?
Login with Facebook
Home » Courses » Smooth Operator » There Are Many Ways To Say No
Subscribe for updates.
* New to us? log in with Facebook and get a free day pass

There Are Many Ways To Say No

In this video we'll take another look at working with not (!): so far we used our '!' operator while comparing variables. (a!=b). In this video we'll look at another way to work with negative equations in ActionScript - !(a==b)

After learning about AND (&&) and OR (||) operators, now it is time to understand what a NOT operator is. A NOT operator can be defined as the negation of any statement. Most of the math text books have the symbol (~) for the NOT operator, but in programming we use the exclamation mark (!) to denote the NOT logical operator.

NOT Operator (!) (Complement of a statement)

The NOT operator gives the complement of any statement when it is applied. For example, if we write trace(!true), the answer would be false because in terms of Boolean values, false is the compliment of true. This is the reason why a NOT symbol before an equality sign checks for explicit inequality (!==). As we get familiar with this operator, we'll understand how this operator is used in various forms. Here we'll list a few of these before moving to the next video.

Various Ways To Use NOT operator (!)

Firstly, we know that trace(!true) is false. But if we write trace(!true==false), this equation is split before giving the final result, trace(false==false) which is true of course. The same equation can be written like this as well, trace(!(false==true)). Here the result is same as the equation simplified to trace(!(false)) which gives the result as true. Consider another example trace(!(0)). We are using extra brackets just to avoid mixing up variables which may lead to confusion in big equations. This equation is converted to a Boolean form, trace(!(false)), since 0 is the value used for false. So the final result of trace(!0) is true.

NOT Operator (!) using Variables

There are a few important things to note while using the NOT Operator with variables. For example, take a variable isTrue which has a Boolean value 'true' assigned to it. We can write trace(!isTrue) to find the compliment of true which is false. But when we use isTrue further in the program, its value is not altered permanently due to changes made by the NOT Operator. The change is temporary for the particular line and the variable never loses its original assigned value. But if we want to change the value permanently, we must use the assignment operator along with NOT Operator. For instance, when we write isTrue = !isTrue, this will assign a value to the variable which is its compliment. In this case the value of trace(isTrue) changes from true to false.

Got A Question?

'I love being Prime'

Have a question but don't want to ask it publicly? If you are a prime member just ask right here and we will get back to you within 48 hours. Not prime yet? no worries you can ask publicly below.

Act now while we have available seating

Our on line school is private, affordable and interactive with trainer support.
Act now save your seat before someone else takes yours.
Act now