The if statement in arduino code is the same way in which we use in english language. The if statement checks if the code written in the condition is true, then the statements written in it will not be executed.

Example:

If (a>b)  digitalWrite(LEDpin, HIGH);

Here, two variables a and b are compared, if a is greater than b, then LEDpin is dumped with HIGH.

The else if statement in arduino code checks if the code written in the if condition is false,and the condition written in the else if statement is true, then the statements written in the else if statements is executed.

Example:

If (a>b)  digitalWrite(LEDpin, HIGH);

else if (b<a) digitalWrite(LEDpin, LOW);

Here, two variables a,b are compared if a is greater than b, then LEDpin is dumped with HIGH. Else if b is greater than a, then LEDpin is dumped with LOW.

The else statement in arduino code checks if the code written in the if condition is false, then the statements written in the else statements is executed.

Example:

If (a>b)  digitalWrite(LEDpin, HIGH);

else (b<a) digitalWrite(LEDpin, LOW);

Here, two variables a,b are compared if a is greater than b, then LEDpin is dumped with HIGH. Else LEDpin is dumped with LOW.

Categories: Arduino

0 Comments

Leave a Reply