# If, Else If Statement

## How to Compare Values and Make Logical BooleanÂ Decisions with ActionScript

Conditional Statements are used to test equations to see if they are true or false. If the statement is true, one event happens. A false outcome would drive a different event.

There are multiple Conditional Statements in ActionScript. For more information, see topics, If Statement, If, Else Statement, If, Else If, Else Statement, or Switch Statement.

In this example we will demonstrate the If, Else If Statement.

#### Conditional Comparisons

Often times values are compared to determine if one is larger, they are equal, or not equal to each other. The following is a list of ActionScript comparisons. The And and Or symbols are used with more complex comparisons.

Equals (==)

Not Equal To (!=)

Greater Than (>)

Greater Than or Equal To (>=)

Less Than (<)

Less Than or Equal To (<=)

Or (||)

And (&&)

#### Step One

Open a new document and name the default layer, Actions.

#### Step Two

Option double-click (PC - Alt double click) the first keyframe of the Actions layer to open the ActionScript panel.

#### Step Three

Copy/Paste the following code in the ActionScript Panel:

var value01:uint=3;

var value02:uint=3;

var value03:uint=4;

var value04:uint=4;

if(value01 < value02 && value03 == value04) {

trace("This is true statement #1")

} else if (value01 == value02) {

trace("This is true statement #2")

};

#### Step Four

Click the Auto Format icon in the Actions panel.

Step Five

Test your movie by pressing Cmd/Return (PC - Ctrl/Enter). This is a true statement #2 should appear in the Output panel.

#### Dissecting the Code

The first four lines establish four new variables named value01, value02, value03, and value04. Each of the variables is set to a starting value.

The if statement asks, is 3 less than 3 (no) and is 4 equal to 4 (yes)? Since the statement is false, we move on to the next question. The else if questions if value01 equals value02 (yes). Since it is true, the trace statement runs and This is true statement #2 appears in the Output panel.

If you were to set the value01 variable to 2, it would make the the first statement true and This is a true statement #1 would appear in the Output panel.