title: Conditional variable setting
body: <p>I need to set a variable depending on a condition. But since variables are immutable, I find myself in a sticky situation having to repeat code. What I'd like to do is:</p>
  
  <pre><code>def doSomething(x:Int):Int = {
    if(x==1){
      val player="Andy"
    } else {
      val player="Rob"
    }
    getSomeValue(player) // Another function
  }
  </code></pre>
  
  <p>But the variable "player" is no longer in scope. Only way I see is to call the function "getSomeValue" in both the condition blocks, but that's not something I'd like to do. How do I get around this using immutable variables?</p>