````

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 can have zero or one else statement and it must come after any else if's.
  • An if can have zero to many else if statements and they must come before the else.
  • Once an else if succeeds, none of the remaining else if or else statements will be tested.

if … else if …else Statements Syntax

if (expression_1) {
   Block of statements;
}

else if(expression_2) {
   Block of statements;
}
.
.
.

else {
   Block of statements;
}

if … else if … else Statement Execution Sequence

If Else If Else Statement

Example

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

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 */
   else if ((A == B )||( B < c) ) 
/* if condition is true then 
      execute the following statement*/ 
 {
      C = B* A;
   }else
      c++;
}

Related Posts:

  • Arduino - switch case statement Similar to the if statements, switch...case controls the flow of programs by allowing the programmers to specify different codes that should be executed in various conditions. In particular, a switch statement compares the… Read More
  • Intel 8085 Microprocessor architecture v\:* {behavior:url(#default#VML);} o\:* {behavior:url(#default#VML);} w\:* {behavior:url(#default#VML);} .shape {behavior:url(#default#VML);} Intel 8085 is a 8-bit microprocessor. It was the most successful 8-bit micropro… Read More
  • Microcontrollers - 8051 Pin Description The pin diagram of 8051 microcontroller looks as follows − Pins 1 to 8 − These pins are known as Port 1. This port doesn’t serve any other functions. It is internally pulled up, bi-directional I/O port. Pin 9 − It is a … Read More
  • Microcontrollers - 8051 Architecture 8051 microcontroller is designed by Intel in 1981. It is an 8-bit microcontroller. It is built with 40 pins DIP (dual inline package), 4kb of ROM storage and 128 bytes of RAM storage, 2 16-bit timers. It consists of are … Read More
  • 8085 PIN DESCRIPTION Properties: It is a 8-bit microprocessor  Manufactured with N-MOS technology  40 pin IC package  It has 16-bit address bus and thus has 216 = 64 KB addressing capability.  Operate with 3 MHz single-phas… Read More

0 comments:

Post a Comment

 
Powered by Blogger