title: My program executes the else statements even though it should stop on the if statement
body: <p>My program proceeds to the else statement even though the user inputs the correct answer and the if statement is run.</p>
  <pre><code>package dowhileloops;
  
  import java.util.Scanner;
  
  public class DoWhileLoops {
  
      public static void main(String[] args) {
          Scanner in = new Scanner (System.in);
          String res, ans;
          
          System.out.println(&quot;=========================================&quot;);
          System.out.println(&quot;     ****     Do-While Loops     ****    &quot;);
          System.out.println(&quot;=========================================\n&quot;);
          
          do{
              System.out.println(&quot;What is the color of the ocean?&quot;);
              System.out.println(&quot;\nA.) Orange\n\nB.) Green\n\nC.) Blue\n\nD.) Yellow\n\n&quot;);
              System.out.print(&quot;Enter your answer: &quot;);
              res = in.nextLine();
  
              if (res.equalsIgnoreCase(&quot;C&quot;))
                  System.out.println(&quot;You are correct!&quot;);
                  else
                      System.out.println(&quot;You are wrong!&quot;);
                          System.out.println(&quot;Would you like to try again? (Yes/No)&quot;);
                          ans = in.nextLine();
                 
          }while(ans.equalsIgnoreCase(&quot;Yes&quot;));        
      }
      
  }
  </code></pre>
  <p>It proceeds to execute the line
  <code>System.out.println(&quot;Would you like to try again? (Yes/No)&quot;); ans = in.nextLine();</code> even though it should stop at <code>System.out.println(&quot;You are correct!&quot;);</code></p>
  <p>I want the program to terminate after the user types the correct answer &quot;C&quot;</p>