If..else

if..else provides more control over the code execution process than the basic if statement, allowing you to perform several checks combined together.

For example, an analog input can be tested and performed one action if the input is less than 500, or another action if the input is 500 or more. The code might look like this:

if (pinFiveInput < 500) {
  // action A
} else {
  // action B
}

Another way to create transitions with mutually exclusive checks is using the switch case statement.

Else allows you to do something different from the one specified in if, so that you can perform several mutually exclusive checks at once. Each test allows you to go to the next operator after it, not before getting the logical result TRUE.

When a check with the result TRUE is found, the statement block nested in it is started, and then the program ignores all the following lines in the if..else construction. If none of the checks received the result TRUE, by default the block of statements in else is executed, if the latter is present, and the default action is set.

Note that the else if construct can be used with or without a final else and vice versa. An unlimited number of such else if transitions is allowed.

if (pinFiveInput < 500){
  // perform action A
}else if (pinFiveInput >= 1000){
  // perform action B
}else{
  // perform action  C
}

Another way to create transitions with mutually exclusive checks is using the switch case statement.