Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/305.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何退出嵌套循环的iInterior循环_Java_Nested Loops - Fatal编程技术网

Java 如何退出嵌套循环的iInterior循环

Java 如何退出嵌套循环的iInterior循环,java,nested-loops,Java,Nested Loops,我有这个程序,我想知道如何结束嵌套循环的内部循环。具体来说,如果用户选择不继续投掷硬币,我如何返回内部循环选择t并将其返回到外部循环?我已经截断了部分代码,但我不明白如何返回到主循环 *{ Scanner anotherScanner = new Scanner(System.in); boolean usersSelection = false; String c; while (!usersSelection)

我有这个程序,我想知道如何结束嵌套循环的内部循环。具体来说,如果用户选择不继续投掷硬币,我如何返回内部循环选择t并将其返回到外部循环?我已经截断了部分代码,但我不明白如何返回到主循环

*{       
        Scanner anotherScanner = new Scanner(System.in);
        boolean usersSelection = false;
        String c;
        while (!usersSelection)
        {
            System.out.println(""
                    + "Selection: ");
            if (anotherScanner.hasNext("q|Q"))
            {
                c = anotherScanner.next();
                usersSelection = true;
                System.out.println("you have selected to quit. If you wish to resume, reboot the program.");
                break;
            }
            if (anotherScanner.hasNext("t|T"))
            {
                c = anotherScanner.next();
                usersSelection = true;

                Scanner obtain = new Scanner(System.in);

                        System.out.println("Please enter the number of coin flips");
                        int numero = obtain.nextInt();
                        if (numero > 0) {
                            for (int i = 0; i < numero; i++) {

                                int alpha = (int) (Math.random() * 2);
                                int beta = (int) (Math.random() * 2);
                                System.out.println(alpha + " " + beta);
                            }
                        }


                        System.out.println("Would you like to continue? Please enter yes or no.");
                        String response = obtain.next();
                        if(response.equalsIgnoreCase("y") || response.equalsIgnoreCase("yes")) {System.out.print("oh yeah");}

                        if(response.equalsIgnoreCase("no") || response.equalsIgnoreCase("n")) {break;} 

                        else 
                        {
                            String boom = obtain.next();
                            System.out.println("You have entered an invalid option. '"+boom+"' is not a valid option.");
                        }}
                }*

在循环之前放置一个标签:

outer:
while (!usersSelection) {
    // blah blah blah
}
然后更换断路器;带断路器