I want to make an infinite loop of a message and stops it if a user inputs a character for example "x". But its getting an error on the if statement saying that it is an unreachable code. Can someone help me.
import java.util.Scanner;
public class Loop {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
char y;
while (true) {
System.out.println("Good Morning!!!");
}
y = input.next().charAt(0);
if (y == 'y') {
break;
}
}
}