In the Arduino programming language, we make decisions with the if statement. The if statement will check if a condition is true and if so will execute the block of code within the curly brackets.
The following shows the syntax for the if statement:
if (condition) { // Code to execute }
We can use an else statement after the if statement to execute a block of code if the condition is not true.
The following shows the syntax for the if/else statement:
if (condition) { // Code to execute if condition is true } else { // Code to execute if condition is false }
The condition, in the if statement, can be any Boolean value or an operation that returns a Boolean result. You will find that the majority of the if statements in your code will contain comparison operations. Let's look at some code that will illustrate this:
if (varA > varB) { Serial.println...