if
if, which is used in conjunction with a comparison operator, tests whether a certain condition has been reached, such as an input being above a certain number.
if (someVariable > 10) {
// do something here
}
This program tests to see if some variable is greater than 10. If it is, the program takes a particular action. In other words, if the statement in parentheses is true, the statements inside the brackets are run. If not, the program skips over the code.
The brackets may be omitted after an if statement. If this is done, the next line (ended by the semicolon) becomes the only conditional statement.
// all are correct
if (x > 120) digitalWrite(LEDpin, HIGH);
if (x > 120)
digitalWrite(15, HIGH);
if (x > 120) { digitalWrite(15, HIGH); }
if (x > 120){
digitalWrite(15, HIGH);
digitalWrite(16, HIGH);
}
if can also be part of a branching control structure using the if...else construction