Arduino Programming Language: Boolean

Name

Logical operators

Description

&& (logical and): Compares two expressions and returns true only if both evaluate to true. Returns false if one or both evaluate to false.

|| (logical or): Compares two expressions and returns true if one or both evaluate to true. Returns false only if both expressions are false.

!(logical not): Inverts the Boolean value of an expression. Returns true if the expression is false and returns false if the expression is true.

Syntax

expression1 && expression2
expression1 || expression2
!expression

Parameters

  • expression1: any valid expression
  • expression2: any valid expression
  • expression: any valid expression

Usage

Application

Examples

if(a>=10 && a<=20) //return true if a is between 10 and 20
if(a>=10 || b<=20)//return true if either operand is true
if(!x) //is true, if x is false.


Based on the reference originally written by Arduino Community,  wiring.org.co and  arduino.cc