如何在scala中实现break语句?

时间:2017-04-11 14:29:13

标签: scala break

我试图将java类转换为scala但我发现了问题 break声明match case结构。

任何人都可以帮助我以正确的方式做到这一点吗?

以下是代码:

override def keyPressed(event: KeyEvent): Unit = if (Main.getScene.getMario isAlive) event getKeyCode match {

case KeyEvent.VK_RIGHT =>
  if (Main.getScene.getxPos == -1) this setBackgroundPosition(0, this FIRST_BACKGROUND_POSITION, this SECOND_BACKGROUND_POSITION)
  this.setMovement(true, true, this MOVEMENT)
  //break

case KeyEvent.VK_LEFT =>
  if (Main.getScene.getxPos == 4601) this setBackgroundPosition(4600, this FIRST_BACKGROUND_POSITION, this SECOND_BACKGROUND_POSITION)
  this setMovement(true, false, -MOVEMENT)
  //break

case KeyEvent.VK_UP =>
  Main.getScene.getMario.setJumping(true)
  Audio playSound (JUMP_SOUND + Res.AUDIO_EXT)
  //break

case KeyEvent.VK_R =>
  Main.main(Array())
  //break
  }

如您所见,我想在每个案例之后发表一个休息声明。 提前谢谢。

1 个答案:

答案 0 :(得分:4)

Scala的<script type="text/javascript" src="js/mainJSCode.js"></script> <script type="text/javascript"> var grabCode = []; if(something==true) { function loadScript(url, callback) { var head = document.getElementsByTagName('head')[0]; var script = document.createElement('script'); script.type = 'text/javascript'; script.src = url; script.onreadystatechange = callback; script.onload = callback; head.appendChild(script); } loadScript("js/my.js", runJS); function runJS(){ for(var i = 0;i < 100; i++) { grabCode.push(someFunctionInsideHereReturnsStuff()); } alert(grabCode.length); //=100 }; alert(grabCode.length); //=0 for some reason } 将按照您想要的方式运行(它只匹配一个案例)。每个案例后你都不需要match