The if-else-if statement : If statement « Statement « C Tutorial






The general format for the if-else if statement is:

if (condition 1)
   simple or compound statement  
else if (condition 2)
   simple or compound statement  
else if ( condition 3)
   simple or compound statement  
   .....
else if ( conditon n )
   simple or compound statement
#include <stdio.h>

main(){
  int i = 2;

  if(i == 0){
     printf(" i == 0. \n");
  }else if(i == 1){
     printf(" i == 1. \n");
  }else if(i == 2){
     printf(" i == 2. \n");
  }
}
i == 2.








6.3.If statement
6.3.1.if statement
6.3.2.To execute only one statement, opening and closing braces are not required
6.3.3.The if statement: a compound statement
6.3.4.If with else statement
6.3.5.The if-else-if statement
6.3.6.if statement with two else statements
6.3.7.if statement: compare the value from user input
6.3.8.Using nested ifs
6.3.9.Use compound conditions to check for upper and lowercase letters
6.3.10.Checking for a Range of Values
6.3.11.Use isdigit Function in if statement
6.3.12.Operators Used in if Comparisons
6.3.13.if Comparisons and Their Opposites