# Converting 'If else' statement to a 'switch' statement

**URL:** <https://forum.kirupa.com/t/converting-if-else-statement-to-a-switch-statement/265799>\
**Category:** flash\
**Created:** [July 12, 2008, 6:37pm UTC](https://forum.kirupa.com/t/converting-if-else-statement-to-a-switch-statement/265799 "2008-07-12T18:37:53Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![wolcotter](https://avatars.discourse-cdn.com/v4/letter/w/6bbea6/32.png) [@wolcotter](https://forum.kirupa.com/u/wolcotter)\
**Post date:** [July 12, 2008, 6:37pm UTC](https://forum.kirupa.com/t/converting-if-else-statement-to-a-switch-statement/265799/1 "2008-07-12T18:37:53Z")

</div>

I am attempting to convert the following If statement to a Switch statement and I’m unclear as to the details of the execution of it. If someone could help me with this I would be very grateful. Here is the If statement followed by the shell of my attempted switch statement. TIA.

var spotOne:Boolean = true;  
var spotTwo:Boolean = false;  
var spotThree:Boolean = false;  
var spotFour:Boolean = false;

## btn.onRelease = function() { f (spotOne) { ball.slideTo(450, 100, 1); spotOne = false; spotTwo = true; } else if (spotTwo) { ball.slideTo(450, 150, .5); spotTwo = false; spotThree = true; } else if (spotThree) { ball.slideTo(100, 150, 1); spotThree = false; spotFour = true; } else { ball.slideTo(100, 100, 1); spotFour = false; spotOne = true; } };

(attempt at conversion to switch)

var spotOne:Boolean = true;  
var spotTwo:Boolean = false;  
var spotThree:Boolean = false;  
var spotFour:Boolean = false;

btn.onRelease = function() {  
var location:Number = ?

switch(location) {  
case spotOne:  
ball.slideTo(450, 100, 1);  
spotOne = false;  
spotTwo = true;  
break;  
case spotTwo:  
ball.slideTo(450, 150, .5);  
spotTwo = false;  
spotThree = true;  
break;  
case spotThree:  
ball.slideTo(100, 150, 1);  
spotThree = false;  
spotFour = true;  
break;  
case spotFour:  
ball.slideTo(100, 100, 1);  
spotFour = false;  
spotOne = true;  
break;  
}  
 ![](http://forum.kirupa.com/uploads/kirupa/615/b7e0d890f190c4d7.gif)[![](http://www.actionscript.org/forums/images/buttons/report.gif) ![](http://www.actionscript.org/forums/images/misc/progress.gif) [URL=“http://www.actionscript.org/forums/editpost.php3?do=editpost&p=765585”] ![](http://www.actionscript.org/forums/images/buttons/edit.gif)](http://www.actionscript.org/forums/report.php3?p=765585)
