Conditional Statements If/Else

If/ Else Conditional Statement

These are conditional statements. They return a particular task like functions. However, the task depends upon on the circumstance of the Boolean operator .

What are Booleans?

A Boolean has only two values True or False | Yes or No. It works by using Comparison and Logical Operators for the particular task.

The Boolean will ask questions. Is C > D? If yes it will return the value “True” if no it will read “False”.

Let’s Practice The Boolean Operator

  1. Create a Text Layer
  2. Open the Source Text and click on the Stop Watch
  3. Type 3 > 5
    • You are asking, is 3 greater than 5 ?
  4. Hit the return key and After Effects will read your expression.
    • The response is False
  5. Then go back and type 3 < 2
    • Is 3 greater than 2 ?
    • The response is True

Comparison Operators

Comparison Operators are similar to mathematical symbols, but slightly different.

Operator SignsWhat Does It Mean?ExampleResult
==Equal to each other? 4 == 1 false
>Greater than 5 > 9 false
<Less than 6 < 9true
> =Greater than or equal7 > = 9false
< =Less than or equal8 < = 9true
! =Not Equal5 != 6true

Basic formula

  • if (Condition) {Condition True: Result 1;
  • } else {
  • the Condition is False: Result 2;
  • }

What if you have more than one Condition?

Then you will add to conditional statements, a Logical Operator sign. It allows you to connect 2 Conditions and will result in either True or False.

Logical Operator Have 3 Types

Logical OperatorsHow Does It Work?Example
&& And Operator: It checks both conditions to see if they are true. If both are true then it will work, but if either conditions are false it will be false.(3 > 7) && ( 5 > 2) = False
|| Or Operator: Checks to see if either condition is true. It will output the task. (1 < 0.5) || ( 2 > 1) = True, because two is greater than one.
!Not Operator: It inverts the statement and sets it false if it is true and vice versa.!true = false
!false = true

A Conditional Statement with 2 Conditions

  1. Create at Rectangle Layer
  2. Open the Opacity Property and click on the Stop-Watch
  3. Type r = and use the pick whip tool to the rotation property.
    • It should read r = transform.rotation;
  4. Next line type the Conditional Statement
    • if (( r > 10 ) && (r < 50)) {100} else {0};
  5. It reads if the rectangle rotation is greater than 10 degrees and less than 50 degrees have the opacity property to be 100% if neither put it at 0%;