How do i go to a label below?

后端 未结 1 1812
轻奢々
轻奢々 2021-01-26 02:19

So i have this code and i want when the user types A to activate the while(attack) which has is below this code so it doesnt work with continue attack; I placed a label called a

相关标签:
1条回答
  • 2021-01-26 03:25

    Labels don't work like this. In Java, there is no goto label functionality. Labels are used when you have inner loops and you need to break or continue an outer loop, like in the following example:

    outterloop:
    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            // this would break the inner loop and go to the next outter loop iteration
            // break; 
    
            // this would break the outter loop, thus exiting both loops
            // break outterloop; 
    
            // this would jump to the next inner loop iteration
            // continue; 
    
            // this would jump to the next outter loop iteration, exiting the inner loop
            // continue outterloop; 
        }
    }
    

    What you need is to improve your code structure to achieve what you want without the need of labels.


    https://docs.oracle.com/javase/tutorial/java/nutsandbolts/branch.html

    0 讨论(0)
提交回复
热议问题