# The funny thing about "else if"

**URL:** <https://forum.kirupa.com/t/the-funny-thing-about-else-if/301305>\
**Category:** flash\
**Created:** [December 7, 2009, 10:16am UTC](https://forum.kirupa.com/t/the-funny-thing-about-else-if/301305 "2009-12-07T10:16:16Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![IQAndreas](https://avatars.discourse-cdn.com/v4/letter/i/f08c70/32.png) [@IQAndreas](https://forum.kirupa.com/u/IQAndreas)\
**Post date:** [December 7, 2009, 10:16am UTC](https://forum.kirupa.com/t/the-funny-thing-about-else-if/301305/1 "2009-12-07T10:16:16Z")

</div>

Just noticed something funny a few weeks back.

To recap, if statements can be written without brackets. If this is done, the very next line is executed, that only that line if the query is met. Same thing after ‘else’.

```auto
if (you.areGay == true)
   me.runAway();
else
   me.befriend(you);

```

Now, many languages have “else if” as “ifelse” or something instead, all one word. However, let’s take a look at how Flash does it:

```auto
if (you.areGay == true)
   me.runAway();
else if (you.areGay == false)
   me.befriend(you);

```

Notice something funny? Really, the above line can be interpreted as “if, then one line that is executed” followed by “else, then one line that is executed”. On that one line, just so happens to be another if statement. If you put several else if statements in a row, you get the following:

```auto
if (you.areGay == true)
    me.runAwayAndDontTurnMyBackOnYou();
else if (you.areBi == true)
   me.runAway();
else if (you.areSociopath == true)
   me.runFaster();
else
   me.befriend(you);

```

Notice that all the if statements in the above code are really if statements followed by one line, which is another if statement, followed by another one line if statement after the else, etc. When you add proper brackets, you will get the exact same results as below:

```auto
if (you.areGay == true)
{
   me.runAwayAndDontTurnMyBackOnYou();
}
else 
{
   if (you.areBi == true)
   {
      me.runAway();
   }
   else 
   {
      if (you.areSociopath == true)
      {
         me.runFaster();
      }
      else
      {
         me.befriend(you);
      }
   }
}

```

Of course, I prefer the 8 lines to 22, so it is quite convenient.

**Is my guess on how it works and compiles correct? Or is Flash smart enough to treat “else if” differently"?**
