Is there a command in java to make the program go back to the beginning of a loop

后端 未结 5 820
独厮守ぢ
独厮守ぢ 2021-01-22 12:22

I am trying to make a typing adventure kind of game in java, however i need a command at least similar to the one in the title, here is the code

import java.util         


        
5条回答
  •  日久生厌
    2021-01-22 12:27

    You can use the continue statement to continue to the next iteration.

    That said, I don't see a loop in your sample code. You can loop with a for, while or do/while. The do/while loop executes at least once -- which is typically what you want to do when asking the user a question.

    This Java tutorial for Branching Statements provides this example of a continue statement in a for loop.

       for (int i = 0; i < max; i++) {
            // interested only in p's
            if (searchMe.charAt(i) != 'p')
                continue;
    
            // process p's
            numPs++;
        }
    

提交回复
热议问题