title: Do while loop changing variables in Java
body: <p>I've been trying to make a choose your adventure type of program, but I've run into a problem.  I have the whole thing running in a do while loop, and each option is an element in an array is an element. I also have if statements in the do while that can change some elements depending on what the user has already done. Here's an example of what my code looks like:</p>
  
  <pre><code>import java.util.Scanner;
  
  public class MainClass {
      public static void main(String[] args) {
          Scanner input;
          input=new Scanner(System.in);
          boolean run;
          boolean theBoo = false;
          run = true;
          int choice;
          choice = 0;
  
          do {
              String[] theArray;
              theArray = new String[2];
              theArray[0] = "Hello";
  
              if(theBoo){
                  theArray[1] = "Goodbye";
              }
              else{
                  theArray[1] = "Hi";
                  theBoo = true;
              }
              System.out.println(theArray[choice]);
              choice = input.nextInt();
  
          } while(run);
      }
  }
  </code></pre>
  
  <p>For some reason though, it prints out "Goodbye" if you input 1, even though it should print "Hi", as theBoo is false. My question is: why is the do while loop changing the value of my variable, and how do I prevent it from doing so? Thanks!</p>
  
  <p>Edit: Btw, I am new here, so my apologies if I did something wrong.</p>
  
  <p>Edit2: First of all, thanks everyone for the quick answers. I made the changes you recommended, but its still doing the same thing. I updated the code to what it is with the changes.</p>