Java 我如何找到下面的标签?

Java 我如何找到下面的标签?,java,Java,所以我有这个代码,我想当用户输入A时激活while(攻击),而while(攻击)在这个代码下面,所以它不适用于继续攻击;我在while(attack)上放置了一个名为attack:over的标签,但它无法识别它,因为它稍后会被声明 String M2 = JOptionPane.showInputDialog(Name2 + "'s Turn. Here are your options\n 1.Invade \n 2.Buy \n 3.End Turn \n 4.Check Money Bal

所以我有这个代码,我想当用户输入A时激活while(攻击),而while(攻击)在这个代码下面,所以它不适用于继续攻击;我在while(attack)上放置了一个名为attack:over的标签,但它无法识别它,因为它稍后会被声明

String M2 = JOptionPane.showInputDialog(Name2 + "'s Turn. Here are your options\n 1.Invade \n 2.Buy \n 3.End Turn \n 4.Check Money Balance \n 5.Check Soldier Count \n 6.Citizen's Hapinness \n 7.Owned Islands \n 8.Check Rules", "Type the Number of the action you want to take place");
                    if (M2.equals("1")) {
                        String Inv=JOptionPane.showInputDialog(null, "Open up the map and Check the island that you are in! If you dont remember the islands name type B to go back and then go into Owned Islands and come back! Then see the attack option you have and choose where you want to attack.Type A to Attack");
                        if(Inv.equalsIgnoreCase("A")){
                            Attack=false;
                            Attack=true;
                            continue attack;
                        }else{

                            continue P2Menu2;
                        }
                    }
这是播放器键入A时必须开始的代码。感谢您抽出时间:)


标签不是这样工作的。在Java中,没有
goto标签
功能。当您有内部循环并且需要
中断
继续
外部循环时,将使用标签,如以下示例所示:

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; 
    }
}
outterloop:
对于(int i=0;i<10;i++){
对于(int j=0;j<10;j++){
//这将中断内部循环并转到下一个外部循环迭代
//中断;
//这将中断outter循环,从而退出两个循环
//中断环路;
//这将跳转到下一个内部循环迭代
//继续;
//这将跳转到下一个外循环迭代,退出内循环
//继续外环;
}
}
您需要的是改进代码结构,以实现您想要的,而不需要标签



标签不是这样工作的。在Java中,没有
goto标签
功能。当您有内部循环并且需要
中断
继续
外部循环时,将使用标签,如以下示例所示:

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; 
    }
}
outterloop:
对于(int i=0;i<10;i++){
对于(int j=0;j<10;j++){
//这将中断内部循环并转到下一个外部循环迭代
//中断;
//这将中断outter循环,从而退出两个循环
//中断环路;
//这将跳转到下一个内部循环迭代
//继续;
//这将跳转到下一个外循环迭代,退出内循环
//继续外环;
}
}
您需要的是改进代码结构,以实现您想要的,而不需要标签



标签不是这样工作的。在Java中,没有
goto标签
功能。当您有内部循环并且需要
中断
继续
外部循环时,将使用标签,如以下示例所示:

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; 
    }
}
outterloop:
对于(int i=0;i<10;i++){
对于(int j=0;j<10;j++){
//这将中断内部循环并转到下一个外部循环迭代
//中断;
//这将中断outter循环,从而退出两个循环
//中断环路;
//这将跳转到下一个内部循环迭代
//继续;
//这将跳转到下一个外循环迭代,退出内循环
//继续外环;
}
}
您需要的是改进代码结构,以实现您想要的,而不需要标签



标签不是这样工作的。在Java中,没有
goto标签
功能。当您有内部循环并且需要
中断
继续
外部循环时,将使用标签,如以下示例所示:

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; 
    }
}
outterloop:
对于(int i=0;i<10;i++){
对于(int j=0;j<10;j++){
//这将中断内部循环并转到下一个外部循环迭代
//中断;
//这将中断outter循环,从而退出两个循环
//中断环路;
//这将跳转到下一个内部循环迭代
//继续;
//这将跳转到下一个外循环迭代,退出内循环
//继续外环;
}
}
您需要的是改进代码结构,以实现您想要的,而不需要标签



尽可能避免与标签接触/断裂。你用得不恰当。如果您可以粘贴整个代码,那么可能更容易看到您在做什么。将while循环放在一个方法中,然后您可以在任何时候调用它,以尽可能避免使用标签进行cont/break。你用得不恰当。如果您可以粘贴整个代码,那么可能更容易看到您在做什么。将while循环放在一个方法中,然后您可以在任何时候调用它,以尽可能避免使用标签进行cont/break。你用得不恰当。如果您可以粘贴整个代码,那么可能更容易看到您在做什么。将while循环放在一个方法中,然后您可以在任何时候调用它,以尽可能避免使用标签进行cont/break。你用得不恰当。如果您可以粘贴整个代码,那么可能更容易看到您正在做什么。将while循环放在一个方法中,然后您可以随时调用它