In this post, you will learn about **Comparison & Logical Operators** in After Effects. So without any further ado, let’s dive right in!

By the way, I highly recommend that you first check out my if/else statements post before diving into **Comparison & Logical Operators** in After Effects. Prior knowledge of** if/else statements** will help you get more out of this post.

Alright so for this setup I have a **rotation** and **opacity** soloed for the **UKRAMEDIA.COM** logo shape layer.

I also have an expression inside of opacity.

The first portion of the expression is just a comment. That is why it starts with /* and ends with */.

So it doesn’t really do anything. Basically, it is there just to show you visually what the **Comparison & Logical Operators** are.

/*

COMPARISON OPERATORS

== Equal To

!= Not Equal

> Greater Than

>= Greater Than Or Equal To

< Less Than

<= Less Than Or Equal ToLOGICAL OPERATORS

&& and

|| or

! not

*/

We will be plugging these **Comparison & Logical Operators** inside of our **if-else statement** below throughout this post.

if () {

100

} else {

0

}

## Comparison Operator: Equal To ==

The first **Comparison Operator is Equal to ==**. So inside of our **if/else statement** I am going to say if rotation equal to **40**, then I want the **opacity** to be **100%** and if it is not equal to **40**, I want the **opacity** to be **0%** like so:

if (

transform.rotation == 40) {

100

} else {

0

}

Let’s try it out. So right now my **rotation** is set to **0** and because of that, the **opacity** is also set to **0**.

However, if I rotate the **UKRAMEDIA.COM** logo up to **+40**, the **opacity** will change to **100%**.

## Comparison Operator: Not Equal !=

The **Not Equal !=** **Comparison Operator** does the opposite of **Equal ==.** So if I say the **rotation** doesn’t equal **!=** to **+40**. So if the rotation is not **+40**, I want the **opacity** to be **100%** and if it is **+40**, I want the **opacity** to be **0%**.

if (

transform.rotation != 40) {

100

} else {

0

}

Right now the **rotation** is **+40** and it is giving me **0% opacity.**

But if the **rotation** doesn’t equal **+40**, it will give me **100% opacity**.

## Comparison Operator: Greater Than >

Next **Comparison Operator** is **Greater Than**. For this example, I am going to say if the **rotation** is **greater than** **+40**, then I want the **opacity** to be **100%**, if not, I want the **opacity** to be **0%**.

if (

transform.rotation >40) {

100

} else {

0

}

Right now the **rotation** is **greater than +40**, so the **opacity** is at **100%**.

But if we go below **+40**, the **opacity** will change to **0%**.

But here’s the thing. If I set my **rotation** to **+40**, the **opacity** will change to **0%** because **+40** is not greater than **+40** but that’s where this **Greater Than or Equal To** comes in handy.

## Comparison Operator: Greater Than or Equal To >=

So I am going to say if the rotation is **Greater Than or Equal To +40**, the **opacity** is going to be **100%**.

if (

transform.rotation >=40) {

100

} else {

0

}

If our **rotation** is at **+40** or above, the **opacity** will remain at **100%**.

## Comparison Operator: Less Than <

The next **Comparison Operator** is **Less Than**. Now I am going to say if **rotation** is less than **+40**, I want the **opacity** to be **100%**.

if (

transform.rotation <40) {

100

} else {

0

}

Right now the **rotation** is not less than **+40** that is why the **opacity** is set to **0%**.

But if I go below **+40**, the **opacity** will change to **100%**.

## Comparison Operator: Less Than or Equal To <=

The same is with **Less Than or Equal To**. If I say the **rotation** is less than or equal to **+40** and then the **opacity** will be at **100%.**

if (

transform.rotation <=40) {

100

} else {

0

}

That is it for **Comparison Operators** and now let’s go over **Logical Operators.**

## Logical Operator: And &&

For this example, I will say if the **rotation** property is **Greater Than** **+40**, I want the **opacity** to be **100%.**

if (

transform.rotation >40) {

100

} else {

0

}

Right now the **rotation** property is **Greater Than** **+40** and, therefore, the **opacity** is at **100%.**

Let me show you how to incorporate our **&& Logical Operator** with this expression. So I can continue and say and or **&&** if **rotation** is less than or smaller than **+60**, I want the **opacity** to be **100%.**

if (

transform.rotation >40 && transform.rotation < 60) {

100

} else {

0

}

For example, right now our **opacity** property is going to be **100%** between **+40** and **+60.**

So if the rotation is **+30,** the **opacity** will not be **100%,** but as soon as I go past **+40,** the opacity will change to **100%.** If I pass **+60,** the **opacity** will change back to 0%.

That is how you can use **&& Logical Operator.**

## Logical Operator: Or ||

The next **Logical Operator** is or **||**. So I am going to say if the **rotation** property is equal to **+40** or **|| rotation** property is equal to **+50,** or **||** rotation property is equal to **+60.** I can keep going with these or statements. You can have as many as you want.

if (

transform.rotation ==40 || transform.rotation == 50 || transform.rotation == 60) {

100

} else {

0

}

So now, anytime the **rotation** property is **+40, +50,** or **+60,** the **opacity** will be **100%.** If not, the **opacity** will be **0%.**

So that was **Or || Logical Operator** but the next one is **Not.** Let me show you what it does.

## Logical Operator: Not !

First, I am going to set a variable for this example. I will say **X** you are going to equal to **+40,** and inside of the parenthesis, I am going to say **X** is greater than **+40** and be **100% opacity.**

x = 40;

if(x > 40){

100

} else {

0

}

Now I know **X** is not bigger than **+40,** so the **opacity** will not be **100%.** It is going to be a false statement. It going to be** 0.**

The **Not Logical Operator** basically reverses our statement. **It will make a true statement false and if you have a false statement, the Not Logical Operator will make it true.**

So right now we have a false statement because **X** is not bigger than **+40.**

To add a **Not Logical Operator,** we first need to add extra parenthesis to the if statement and then say if then put **Not** in front of it. So instead of the outcome being **0**, it will now be **100%** because the **Not Logical Operator** reverses everything.

x = 40;

if(!(x > 40)){

100

} else {

0

}

I hope you found this post useful. If you would like to learn more about Expression and how it can speed up your workflow in After Effects, then check out my Learn After Effects Expressions Course.

## Download Project File

[sociallocker]