Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3427442
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T06:50:13+00:00 2026-05-18T06:50:13+00:00

I’ve created a case switch option list, First option list option 1 go to

  • 0

I’ve created a case switch option list,

First option list
option 1 go to option list A
option 2 go to option list B
option 3 haven’t decided what this will do yet C
option 4 Exit

if option 1 is selected
option 1 Do A
option 2 Do B
option 3 Do C
option 4 previous Menu
option 5 Exit

So basically its a switch inside a switch. The bit I’m stuck on is returning to the previous menu.

while (true) {
        System.out.println("Choose which Sort type to use\n");
        System.out.println("(1): Option 1 - do something\n(2): Option 2 - do something else\n(3): Option 3 - Something Cool\n(4): Exit");
        option = in.nextInt();

        if (option == 4) {
            System.exit(0);
        }


        switch (option) {

        case 1:

            while (true) {
        System.out.println("Choose which Sort type to use\n");
        System.out.println("(1): Option 1 - do something\n(2): Option 2 - Do something else\n(3): Option 3 - Something Cool\n(4): Exit");
        option = in.nextInt();

        if (option == 4) {
            System.exit(0);
        }


        switch (option) {

        case 1:

            while (true) {

            System.out.println("Choose which Sort type to use\n");
            System.out.println("(1): Option 1 -something\n(2): Option 2 - something else\n(3): Option 3 - something else\n(4): Option 4 - Previous Menu\n(5): Exit\n");
            option = in.nextInt();
            if (option == 5) {
                System.exit(0);
            }


            switch (option) {

            case 1:

                break;
            case 2:

                break;
            case 3:

                break;
            case 4:

            default:
                System.out.print("Please enter a valid option 1, 2 or 3");
                break;
            }//end of switch


        }//end of while loop





        case 2:
            while (true) {

                System.out.println("Choose which something type to use\n");
                System.out.println("(1): Option 1 - something\n(2): Option 2 - something\n(3): Option 3 - something\n(4): Exit");
                option = in.nextInt();
                if (option == 4) {
                    System.exit(0);
                }


                switch (option) {

                case 1:

                    break;
                case 2:

                    break;
                case 3:


                    break;
                default:
                    System.out.print("Please enter a valid option 1, 2 or 3");
                    break;
                }//end of switch


            }//end of while loop











        case 3:

            break;
        default:
            System.out.print("Please enter a valid option 1, 2 or 3");
            break;
        }//end of switch

        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T06:50:14+00:00Added an answer on May 18, 2026 at 6:50 am

    Put the nested switch inside a method. When you’re done with its loop, return.

    while (true)
    {
        option = ...;
        switch (option)
        {
        case 0:
            submenu();
            break;
        // ...
        }
    }
    
    // later
    public void submenu()
    {
        while (true)
        {
            option = ...;
            switch (option)
            {
            case 0:
                return;
                break;
            // ...
            }
        }
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.