2009

Table Of Contents
When time is greater than or equal to 2, the translateY position of Balloon
becomes 2 minus 2, which is 0. As time increases beyond 2 seconds, the
translateY position increases in the same increments that time increases.
4 Stop the animation and go to the start time.
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 animations 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, youll also improve the execution speed of
580 | Chapter 12 Expressions