title: How to convert a do while loop to a while loop
body: <p><strong>How do I convert my do-while loop to a while loop?</strong></p>
  
  <pre><code>int numAttempts = 0;
  
  do
  {
      System.out.println("Do you want to convert to Peso or Yen?");
      pesoOrYen = readKeyboard.nextLine();
  
      if(pesoOrYen.equalsIgnoreCase("Peso")||pesoOrYen.equalsIgnoreCase("Yen"))
      {
          notPesoOrYen = false;
      }
      else if (numAttempts &lt; 2)
      {
          System.out.println("Sorry, but '"+pesoOrYen+"' is not a valid currency type. Try again:");
          notPesoOrYen = true; 
      }
  
      numAttempts++;
  
  } while(notPesoOrYen==true &amp;&amp; numAttempts &lt; 3);
  </code></pre>
  
  <p>I tried to do <code>while(notPesoOrYen==true &amp;&amp; numAttempts &lt; 3)</code> then the statement but it did not work.</p>
  
  <p><strong>MY FULL CODE</strong></p>
  
  <p>package currencyconverter;</p>
  
  <p>import java.util.Scanner;
  import java.text.NumberFormat;</p>
  
  <p>public class CurrencyConverter 
  {</p>
  
  <pre><code>public static void main(String[] args) 
  {
      Scanner readKeyboard = new Scanner(System.in);
  
      double doubleUsersCaptial;
      boolean notPesoOrYen=true;
      String pesoOrYen;
      double usersConvertedCapital;
      boolean userInputToRunProgramAgain=true;
  
      final double US_DOLLAR_TO_PESO = 13.14;
      final double US_DOLLAR_TO_YEN  = 106.02;
  
  
      do
      {
  
          System.out.println    ("How much money in US dollars do you have?");
          String usersCaptial    = readKeyboard.nextLine();
          doubleUsersCaptial = Double.parseDouble(usersCaptial);
  
          int numAttempts = 0;
  
          do
          {
              System.out.println    ("Do you want to convert to Peso or Yen?");
              pesoOrYen      = readKeyboard.nextLine();
  
  
  
              if(pesoOrYen.equalsIgnoreCase("Peso")||pesoOrYen.equalsIgnoreCase("Yen"))
              {
                  notPesoOrYen = false;
              }
              else if (numAttempts &lt; 2)
              {
                  System.out.println("Sorry, but '"+pesoOrYen+"' is not a valid currency type. Try again:");
                  notPesoOrYen = true; 
  
              }
          numAttempts++;
          }while(notPesoOrYen==true &amp;&amp; numAttempts &lt; 3);
  
          if(numAttempts==3)
          {
              System.out.println("Sorry, but '"+pesoOrYen+"' is not a valid currency type.");
              System.out.println("You entered the wrong currency type too many times\nGood Bye");
              System.exit(0); 
          }
  
          if (pesoOrYen.equalsIgnoreCase("Peso"))
          {
              usersConvertedCapital = doubleUsersCaptial*US_DOLLAR_TO_PESO;
          }
          else 
          {
              usersConvertedCapital = doubleUsersCaptial*US_DOLLAR_TO_YEN;
          }
  
  
          NumberFormat formatter     = NumberFormat.getCurrencyInstance();
          String formatUsersCaptial = formatter.format(doubleUsersCaptial);
          String formatUsersConvertedCapital  = formatter.format(usersConvertedCapital);
  
  
          System.out.println(formatUsersCaptial+"US Dollars = "
                            +formatUsersConvertedCapital+" "+pesoOrYen);
          System.out.println("Would you like to run the Program Again?(enter 'yes' or 'no')");
          String runProgramAgain = readKeyboard.nextLine();
  
  
          if (runProgramAgain.equalsIgnoreCase("yes"))
          {
              userInputToRunProgramAgain = true;
          }
          else if (runProgramAgain.equalsIgnoreCase("no"))
          {
              System.out.println("Goood Bye");
              System.exit(0);    
          }
  
          else
          {
              System.out.println ("You entered something other than 'yes' or 'no'\n"
                                 +"Good Bye");
              System.exit(0);
          }
      }while (userInputToRunProgramAgain==true);
  }
  </code></pre>
  
  <p>}</p>