2 myq 26 myq_26 于 2013.05.22 13:23 提问

如何停止 if 语句中的 "continue"

我创建了一个 if 语句,如果是 true 就继续运行。我想停止 "continue" ,然后创建另一个语句。例如 touchdown 和 touchup. 如何实现?

private void updateRunning(float deltaTime) {
    List<TouchEvent> touchEvents = game.getInput().getTouchEvents();
    int len = touchEvents.size();
        for (int i = 0; i < len; i++) {
        TouchEvent event = touchEvents.get(i);
        if (event.type != TouchEvent.TOUCH_UP)
            continue;
        world.doodle.DOODLE_Y = 3;
        touchPoint.set(event.x, event.y);
        guiCam.touchToWorld(touchPoint);
        if (OverlapTester.pointInRectangle(pauseBounds, touchPoint)) {
            Assets.clicks();
            state = GAME_PAUSED;
            return;
        }
     }
    world.update(deltaTime, game.getInput().getAccelX());
    if (world.score != lastScore) {
        lastScore = world.score;
        scoreString = "" + lastScore;
    }
    if (world.state == World.WORLD_STATE_NEXT_LEVEL) {
        state = GAME_LEVEL_END;
    }
    if (world.state == World.WORLD_STATE_GAME_OVER) {
        state = GAME_OVER;
        if (lastScore >= Settings.highscores[4])
            scoreString = "new highscore: " + lastScore;
        else
            scoreString = "score: " + lastScore;
        Settings.addScore(lastScore);
        Settings.save(game.getFileIO());
    }
}

2个回答

franzhong
franzhong   2013.05.22 13:42
已采纳

就将那两句注释掉,在此创建好了就break就跳出循环了
不过要注意,看样子,一两次循环你不一定能得到你想要的条件
要不然不会for都查一遍了
也可以这样细分效率能高一些

switch(event.type){
  case TouchEvent.TOUCH_DOWN:
  //
  break;
  case TouchEvent.TOUCH_UP:
  //    
  break;
  default:
        continue;
  break;
  }
CSDN_Ask
CSDN_Ask   2013.05.22 15:26
if (event.type == TouchEvent.TOUCH_UP) {
    /* do something for TOUCH_UP event */
} else if (event.type == TouchEvent.TOUCH_DOWN) {
    /* do something for TOUCH_DOWN event */
} else {
    /* do something else */
}
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!