title: Breaking out of an infinite loop after a user inputs a character
body: <p>I want to make an infinite loop of a message and stops it if a user inputs a character for example &quot;x&quot;. But its getting an error on the if statement saying that it is an unreachable code. Can someone help me.</p>
  <pre><code>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(&quot;Good Morning!!!&quot;);
          }
          y = input.next().charAt(0);
          if (y == 'y') {
              break;
          }
      }   
  }
  </code></pre>