&& versus & : Logical Operators « Operators « Java Tutorial






Conditional && will not evaluate the right-hand operand if the left-hand operand is false.

public class MainClass {

  public static void main(String[] arg) {
    int value = 8;
    int count = 10;
    int limit = 11;

    if (++value % 2 == 0 & ++count < limit) {
      System.out.println("here");
      System.out.println(value);
      System.out.println(count);
    }
    System.out.println("there");
    System.out.println(value);
    System.out.println(count);
  }
}
there
9
11








3.7.Logical Operators
3.7.1.Boolean Logical Operators
3.7.2.The following table shows the effect of each logical operation
3.7.3.Logical operators in action
3.7.4.Demonstrate the boolean logical operators
3.7.5.Logical Operators
3.7.6.AND operator
3.7.7.&& versus &
3.7.8.Logical OR Operations
3.7.9.Boolean NOT Operations: applies to one boolean operand
3.7.10.Demonstrates short-circuiting behavior