title: Can't set a variable inside a while loop
body: <p>New to Java, sorry if this is a stupid question. I'd like to assign new values to a couple of variables from inside a <code>while</code> loop, but that's not working. I'm getting an error "The local variable <code>newString</code> may not have been initialized" when trying to compile. Here's an example:</p>
  
  <pre><code>public class Test {
  
      public static String example() {
          String first;
          String second;
          String newString;
          int start = 1;
  
          while (start&lt;5) {
              if (start&lt;4) {
                  first = "hello";
                  second = "world";
                  newString = first + second;
              }
              start += 1;
          }
          return newString;
      }
  
      public static void main(String[] args) {
              System.out.println(example());
      }
  }
  </code></pre>