title: Java Do While loop
body: <p>I know that in a while loop the do loop gets iterate first then the condition is checked. But Why does this code print 3, shouldn't it go into an infinity loop? But if i replace b = !b with true. It does go into an infinite loop. why is that? (i am a newbie so i could be missing something dumb)</p>
  
  <pre><code>public static void main(String[] args) {
     boolean b = false;
     int i = 1;
      do{
          i++ ;
      } while (b = !b);           //shouldn't this loops forever, if i put true, it does loop for ever why?
      System.out.println( i );    //prints 3
  }
  </code></pre>