Arduino - Instruction If

Il prend une expression entre parenthèses et une instruction ou un bloc d'instructions. Si l'expression est vraie, l'instruction ou le bloc d'instructions est exécuté sinon ces instructions sont ignorées.

Différentes formes de déclaration if

Form 1

if (expression)
   statement;

Vous pouvez utiliser l'instruction if sans accolades {} si vous avez une instruction.

Form 2

if (expression) {
   Block of statements;
}

Instruction if - Séquence d'exécution

Exemple

/* Global variable definition */
int A = 5 ;
int B = 9 ;

Void setup () {

}

Void loop () {
   /* check the boolean condition */
   if (A > B) /* if condition is true then execute the following statement*/
   A++;
   /* check the boolean condition */
   If ( ( A < B ) && ( B != 0 )) /* if condition is true then execute the following statement*/ { 
      A += B;
      B--;
   }
}