jeudi 5 octobre 2017

Continuously ask for a user input

I have two available options for a user to input, and what I am trying to accomplish is if the user does not enter either of the inputs the program will continuously ask them again until they enter a valid one. Here is the code right now

String userLIB = user_input.next();
    if (userLIB.contentEquals(UBC.acro)){
        printDetails(UBC);
    } else {
        if (userLIB.contentEquals(ORL.acro)){
            printDetails(ORL);
        } else {
            while (!userLIB.contentEquals(UBC.acro) || !userLIB.contentEquals(ORL.acro)){
            System.out.println("Invalid input");
            break;
            }
        }
    }

I have a break to keep the code from looping the "Invalid input" indefinetly but it just ends the program right now which isn't what I want to happen. Is there a way to make the program go back to the start of the if statement?

Aucun commentaire:

Enregistrer un commentaire