Q:

Else loop in java

So I'm making a java program that will ask the user "how are you" and if the criteria in the if and if else statements isn't met then it should loop but i'm not sure how to implement the loop to make it so when the user doesn't input anything that is in both of the if statements it should repeat the code
Here is my code
import java.util.Scanner;

public class simplechatbot {

    private static Scanner scanner;

    public static void main(String args[]) {

        scanner = new Scanner(System.in);

        System.out.print("What is your name");
        String greeting = scanner.nextLine();
        System.out.print("Hi" + " " + greeting + ", ");

        System.out.print("How are you");
        String howareyou = scanner.nextLine();

        if (howareyou.equalsIgnoreCase("good")) {
            System.out.print("Thats good to hear!");
        } else if (howareyou.equalsIgnoreCase("not good")) {
            System.out.print("Unfortunate");
        } else {
             /*
                this is where I want to put the loop that goes back to asking the user
                "how are you" until they say something which matches the criteria
             */
        }
    }
}

A:

Use a while true loop forever unless one of the break conditions is met:
import java.util.Scanner;

public class SimpleChatBot {

    public static void main(String args[]) {
        try (Scanner scanner = new Scanner(System.in)) {
            while (true) {
                System.out.print("What is your name");
                String greeting = scanner.nextLine();
                System.out.print("Hi" + " " + greeting + ", ");

                System.out.print("How are you");
                String howareyou = scanner.nextLine();
                if (howareyou.equalsIgnoreCase("good")) {
                    System.out.print("Thats good to hear!");
                    break;
                } else if (howareyou.equalsIgnoreCase("not good")) {
                    System.out.print("Unfortunate");
                    break;
                }
            }
        }
    }
}

