title: Boolean example return unexpected answer
body: <p>I was going through java test given on <a href="https://www.indiabix.com/online-test" rel="nofollow noreferrer">indiabix</a> and there a boolean question went something like -</p>
  
  <pre><code>public class If2 
  {
      static boolean b1, b2;
      public static void main(String [] args) 
      {
          int x = 0;
          if ( !b1 ) /* Line 7 */
          {
              if ( !b2 ) /* Line 9 */
              {
                  b1 = true;
                  x++;
                  if ( 5 &gt; 6 ) 
                  {
                      x++;
                  }
                  if ( !b1 ) /* Line 17 */
                      x = x + 10;
                  else if ( b2 = true ) /* Line 19 */
                      x = x + 100;
                  else if ( b1 | b2 ) /* Line 21 */
                      x = x + 1000;
              }
          }
          System.out.println(x);
      }
  }
  </code></pre>
  
  <p>Now the explnation says -
  As instance variables, b1 and b2 are initialized to false. The if tests on lines 7 and 9 are successful so b1 is set to true and x is incremented. The next if test to succeed is on line 19 (note that the code is not testing to see if b2 is true, it is setting b2 to be true). Since line 19 was successful, subsequent else-if's (line 21) will be skipped. Thus the answer comes to 101 and not 111. But why would the <code>if ( !b1 )</code> on Line 17 be ignored. Is it that the <code>if ( !b1 )</code> on Line 7 is only considered true and later appearance of <code>if ( !b1 )</code> on Line 17 is ignored. My understanding says answer should be 111 and not 101.</p>