Arduino - Comparison Operators


Advertisements

Assume variable A holds 10 and variable B holds 20 then −

Operator name Operator simple Description Example
equal to = = Checks if the value of two operands is equal or not, if yes then condition becomes true. (A == B) is not true
not equal to ! = Checks if the value of two operands is equal or not, if values are not equal then condition becomes true. (A != B) is true
less than < Checks if the value of left operand is less than the value of right operand, if yes then condition becomes true. (A < B) is true
greater than > Checks if the value of left operand is greater than the value of right operand, if yes then condition becomes true. (A > B) is not true
less than or equal to < = Checks if the value of left operand is less than or equal to the value of right operand, if yes then condition becomes true. (A <= B) is true
greater than or equal to > = Checks if the value of left operand is greater than or equal to the value of right operand, if yes then condition becomes true. (A >= B) is not true

Example

void loop () { 
   int a = 9,b = 4
   bool c = false;
   if(a == b)
      c = true;
   else
      c = false;

   if(a != b)
      c = true;
   else
      c = false;
   
   if(a < b)
      c = true;
   else
      c = false;
   
   if(a > b)
      c = true;
   else
      c = false;
   
   if(a <= b)
      c = true;
   else
      c = false;
   
   if(a >= b)
      c = true;
   else
      c = false;
}

Result

c = false
c = true
c = false
c = true
c = false
c = false
arduino_operators.htm

Useful Video Courses


Video

Learn to Build Advanced Embedded Systems using Arduino

65 Lectures 6.5 hours

Amit Rana

Video

Learn Arduino using simple drag and drop Blocks

43 Lectures 3 hours

Amit Rana

Video

Design 3D Printed Enclosure for Arduino Boards Fusion 360

20 Lectures 2 hours

Ashraf Said

Video

ESP32 + Arduino Interfacing: A Step by Step Course

19 Lectures 1.5 hours

Ashraf Said

Video

Make PIC microcontroller based Arduino Development Board

11 Lectures 47 mins

Ashraf Said

Video

Arduino Vs Raspberry PI Vs PIC Microcontroller

9 Lectures 41 mins

Ashraf Said

Advertisements