当用户键入"完成"时,我希望我的while循环停止

-4 java loops

它是一个Text speak转换器,它可以工作,直到我希望它在用户说"完成"时结束.我会用什么命令?

package textspeak;

import java.util.Scanner;


public class TextSpeak {
    byte textspeak;

    public static void main(String[] args) {

            String brb = new String("brb");
            String omw = new String("omw");
            String btw = new String("btw");
            String lol = new String("lol");
            String omg = new String("omg");
            String rofl = new String("rofl");
            String fyi = new String("fyi");
            String ftw = new String("ftw");
            String idk = new String("idk");
            String jk = new String("jk");
            String ikr = new String("ikr");
            String smh = new String("smh");
            String ttyl = new String("ttyl");
            String rn = new String("rn");
            String nvm = new String("nvm");
            String ily = new String("ily");
            String done = new String("done");

            System.out.println("Hello! I convert 'text speak' into real english. Type in a commonly used shortcut for a word or phrase and I'll try to convert it. Type 'done' when you're done.");
            Scanner scan = new Scanner(System.in);
            String user_input = scan.nextLine();
            while (!user_input.isEmpty()){  <<<<<<<<<<<<<<<<<What command do I need to put here?
            user_input = scan.nextLine();
                if (user_input.equals(brb)){
                System.out.println("Be Right Back");}
                if (user_input.equals(omw)){
                    System.out.println("On My way");}
                if (user_input.equals(btw)){
                    System.out.println("By The Way");}
                if (user_input.equals(lol)){
                    System.out.println("Laughing Out Loud");}
                if (user_input.equals(omg)){
                    System.out.println("Oh My Gosh");}
                if (user_input.equals(rofl)){
                    System.out.println("Rolling On the Floor Laughing");}
                if (user_input.equals(fyi)){
                    System.out.println("For Your Information");}
                if (user_input.equals(ftw)){
                    System.out.println("For The Win");}
                if (user_input.equals(idk)){
                    System.out.println("I Don't Know");}
                if (user_input.equals(jk)){
                    System.out.println("Just Kidding");}
                if (user_input.equals(ikr)){
                    System.out.println("I Know, Right?");}
                if (user_input.equals(smh)){
                    System.out.println("Shaking My Head");}
                if (user_input.equals(ttyl)){
                    System.out.println("Talk To You Later");}
                if (user_input.equals(rn)){
                    System.out.println("Right Now");}
                if (user_input.equals(nvm)){
                    System.out.println("Nevermind");}
                if (user_input.equals(ily)){
                    System.out.println("I Love You");} 
                                    }
            }//end of while loop
        }
Run Code Online (Sandbox Code Playgroud)

Anu*_*oob 6

尝试做:

while (!user_input.equals("done"))
Run Code Online (Sandbox Code Playgroud)

或者杰伊说你可以break在循环中:

if (user_input.equals("done")) {
    break;
}
Run Code Online (Sandbox Code Playgroud)

这会把你带到循环之外.例如:

while (true) {
    break;
    System.out.println("Inside");
}
System.out.println("Outside");
Run Code Online (Sandbox Code Playgroud)

打印只是: