Using else statements
 
 
 

The expression achieved the desired result, but with unnecessary complexity. You can use an if-else statement to make the statement more compact and easier to read.

  1. Change the expression to this:
    if (time < 2)
    	Balloon.translateY = 0;
    if (time < 2)
    	Balloon.scaleY = time;
    else
    	Balloon.translateY = time - 2;
    
  2. Click Edit.
  3. Play the animation.

    The animation plays back exactly as before.

    This additional variation on the if conditional statement includes the else statement. It is used as an option when the if statement condition is not true. The else keyword sets Balloon.translateY to time - 2 when (time < 2) is false. In English terms, the combination of the if and else statements means: If time is less than two seconds, set Balloon.scaleY to the value of time. Otherwise (when time is greater than or equal to two seconds), set Balloon.translateY to time minus two.

    At any instant in the animation’s playback, either Balloon.scaleY = time executes or Balloon.translateY = time - 2 executes. Under no circumstances can they both execute. The else statement executes only when the if condition that precedes it is false.

    The first if statement executes whenever time equals 0. It is unrelated to the if-else statements.

    Using else statements instead of multiple if statements makes an expression simpler to read. If you use an if-else construction instead of a lengthy list of if statements, you’ll also improve the execution speed of the expression. This improves your animation’s playback and rendering speed.

    Either expression is valid. If using the if-else construction seems confusing, stick with multiple if statements.

    You can accomplish most expression animation tasks with several if statements strung after one another.

  4. Stop the animation and go to the start time.