2 Replies Latest reply on Jan 30, 2012 1:56 PM by mr.mango97

# if, else and elseif commands

So just for clarity of if, else and elseif....

Lets say I have enetered a simple math equasion typed out in my program (see below)

var a:iunt = 5;

a = a + 5 * 2 + 20; //answer is 40

I then could add an if and else statement (see below)

if (a == 24) {

trace ( "The Answer is 24" );

}

else {

trace ("The Answer is not 24");

}

Where I get confused is the elseif statement. Btw is their a space between the word else and if? How do you write the elseif statement (what would the code look like if I wanted it to say "The answer is less than 50" and for that sentance to be true?

• ###### 1. Re: if, else and elseif commands

There is a space between the "else" and the "if".

if (a == 24)

else if (a < 50)

trace("The answer is not 24 but is less than 50")

else if (a > 100)

trace("The answer is more than 100")

else

trace("The answer is not 24, is not less than 50, and is not more than 100")