View Single Post
  #2  
Old 03-01-2011, 02:26 AM
WhiteDragon WhiteDragon is offline
Banned
Join Date: Feb 2007
Posts: 1,002
WhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to behold
It's just a different way to write an if-else when you're working with a single variable (a in this case).

That switch statement in your code translates to

PHP Code:
  if (== "0") { 
    
player.-= this.speed
  } else if (
== "1") {
    
player.-= this.speed
  } else if (
== "2") {
    
player.+= this.speed
  } else if (
== "3") {
    
player.+= this.speed
  } 
You can do slightly more complicated logic with switch statements, but I personally think those more complex uses of switch just makes things more confusing and bug-prone.
Reply With Quote