````

Arduino - If …else statement

An if statement can be followed by an optional else statement, which executes when the expression is false.

if … else Statement Syntax

if (expression) {
   Block of statements;
}
else {
   Block of statements;
}

if…else Statement – Execution Sequence

If Else Statement

Example

/* 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++;
   }else {
      B -= A;
   }
}

Related Posts:

  • Arduino - Control Statements Decision making structures require that the programmer specify one or more conditions to be evaluated or tested by the program. It should be along with a statement or statements to be executed if the condition is determin… Read More
  • Arduino - Operators An operator is a symbol that tells the compiler to perform specific mathematical or logical functions. C language is rich in built-in operators and provides the following types of operators − Arithmetic Operators Comparison… Read More
  • Arduino - If…else if …else statement The if statement can be followed by an optional else if...else statement, which is very useful to test various conditions using single if...else if statement. When using if...else if…else statements, keep in mind − An if … Read More
  • Arduino - If …else statement An if statement can be followed by an optional else statement, which executes when the expression is false. if … else Statement Syntax if (expression) { Block of statements; } else { Block of statements; } if…else … Read More
  • Arduino - Conditional Operator ? : The conditional operator ? : is the only ternary operator in C. ? : conditional operator Syntax expression1 ? expression2 : expression3 Expression1 is evaluated first. If its value is true, then expression2 is evaluated a… Read More

0 comments:

Post a Comment

 
Powered by Blogger