ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

# something weird happens when i try to else if statment.

FAQ   •   VIEW ALL
 something weird happens when i try to else if statment. on May 13, 2018 at 12:27:07 pmLast Edited By Assaf Goldlust on May 13, 2018 at 2:33:58 pm

i tried to experiment with multiple conditional
if/else statment.

at first i tried this expression
``` T=Math.floor(time); R=thisLayer.rotation; if(T>=3){[300,300]} else if (T>3&&R>10){[500,500]} else {[100,100]} ```

its seems to be ok except that im not able to get the "[500,500] even when time is bigger then 3 seconds and
and rotation is bigger then 10

and then i tried to reverse the expression:

```T=Math.floor(time); R=thisLayer.rotation; if(R>10&&T>=3){[500,500]} else if (T>3){[300,300]} else {[100,100]}; ```
and its works. any ideas why?

 Re: something weird happens when i try to else if statment.on May 13, 2018 at 4:27:18 pm

In the first one, if T is greater than 3, the first condition is met so it stops checking.

Another way to structure it would be like this:

``` if (T > 3){ if (R > 10){ [500,500]; }else{ [300,300]; } }else{ [100,100]; } ```

Dan

 Re: something weird happens when i try to else if statment.on May 13, 2018 at 4:49:54 pm

i tried something semilar earlier that day.
(in the sense off placing to "if" conditions)

but it didnt work as i expected

if(T>=3){[300,300]}
if (T>3&&R>10){[500,500]} else {[100,100]}

but as if he is ignoring the first condition why?

 Re: something weird happens when i try to else if statment.on May 13, 2018 at 4:57:29 pm

It is not ignored, but the result from the second line overrides the result from line one.

Kalleheikki Kannisto
Senior Graphic Designer

 Re: something weird happens when i try to else if statment.on May 13, 2018 at 4:59:41 pm

It will execute the first statement, but then, no matter the result of the first statement, it will always execute the second statement which will overwrite the result of the first statement.

Dan