title: Alternative for goto in java
body: <p>In a Thread named a I have 2 loops, they both have to stop when flag is false.
  Somthing like that:</p>
  
  <pre><code>boolean flag = true;
  
  t1 = new Thread(new Runnable()
  {
      @Override
      public void run()
      {
          while(flag &amp;&amp; another_condition)
          {
          }
  
          Do_something_that_takes_time
  
          while(flag &amp;&amp; another_condition)
          {
          }
  
      });
  }
  </code></pre>
  
  <p>Let's assume that we entered the first loop and in the middle of the loop run changed to false, now we will move to the "Do_somthing..." lane which might take few seconds to complete and then we will be moved to the second loop.
  In the meantime the value of flag might be changed once again to true! which means I will execute the second loop and I don't wish for that. So is that possible to do something like:</p>
  
  <pre><code>boolean flag = true;
  
  t1 = new Thread(new Runnable()
  {
      @Override
      public void run()
      {
          while(another_condition)
          {
              goto end;
          }
  
          Do_something_that_takes_time
  
          while(flag &amp;&amp; another_condition)
          {
              goto end;
          }
          end:    
      });
  }
  </code></pre>
  
  <p>The code I wrote now of course is not working but it's just to demonstrate my will.
  I know "break" should be the solution but I couldn't come up with a solution by using it.</p>