# Nest if/else in switch statement?

**URL:** <https://forum.kirupa.com/t/nest-if-else-in-switch-statement/245856>\
**Category:** flash\
**Created:** [December 4, 2007, 9:22pm UTC](https://forum.kirupa.com/t/nest-if-else-in-switch-statement/245856 "2007-12-04T21:22:42Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![steve\_b](https://avatars.discourse-cdn.com/v4/letter/s/ee7513/32.png) [@steve\_b](https://forum.kirupa.com/u/steve_b)\
**Post date:** [December 4, 2007, 9:22pm UTC](https://forum.kirupa.com/t/nest-if-else-in-switch-statement/245856/1 "2007-12-04T21:22:42Z")

</div>

Is this possible?

Ive written a piece of code that checks what direction a movieclip is coming from, then plays the next clip in line from the relevant key frame, depending on what type the target movieclip is. I have the following code, but it doesnt seem to “break” when the condition is met, it carries on looping through :-/

```php

switch (type) {
    case "mc_1":    
        
        if (_root.direction == "right") {
            playFrame = 2;
            trace("right");
        } else if (_root.direction == "left") {
            trace("left");
            playFrame = 21;
        } else {
            trace ("gameOver");
        }
    break ;
    
    case "mc_2":
        
        if(_root.direction == "top") {
            playFrame = 2;
            trace("top");
        } else if(_root.direction == "bottom") {
            playFrame = 21;     
            trace("bottom");
        } else {
            trace ("gameOver");
        }
        
        break;

default: 
trace ("gameOver")
}

```

The switch statement is infact much bigger than this (there are 10 types of target movieclip, hence why nesting an if/else would seem to be the best route, rather than writing out more switch cases…
