Name

&& (logical AND)

Description

Compares two expressions and returns true only if both evaluate to true. Returns false if one or both evaluate to false. The following list shows all possible combinations:

true && false // Evaluates false because the second is false
false && true // Evaluates false because the first is false
true && true // Evaluates true because both are true
false && false // Evaluates false because both are false

Examples

  • size(400, 400);
    for (int i = 20; i <= 380; i += 20) {
      if ((i > 140) && (i < 240)) {
        stroke(0);  // Set color to black
      } else {
        stroke(255);  // Set color to white
      }
      line(120, i, 320, i);
    }
    Image output for example 1

Syntax

  • expression1 && expression2

Parameters

  • expression1any valid expression
  • expression2any valid expression