Arduino Programming Language: Else

Name

if...else

Description

Allows multiple tests to be grouped. If a certain condition is verified, an action is performed; otherwise it runs another.

Syntax

if (expression) {
statements1
}else{
statements2
}

Parameters

  • expression: any valid expression that evaluates to true or false
  • statements: one or more statements to be executed

Usage

Application

Note

There may be several blocks else , but only runs that matches the test if. 
You can also use the block else-if that allows you to check one or more conditions

if x(<50){
//do action A
}else if(x>100){
//do action B
}else{
//do action C
}

Examples

if(x>10){
//some action
}else{
//another action
}


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