C - if else if ladder Control Statements

<<Previous

Next >>





if else if

By using if else if ladder, we can test the multiple condition. Here the conditional expressions are evaluated in order. If the condition is true, then that particular statement will be executed. Suppose if none of the condition is true, then default else statement will be executed.

Syntax:

if(conditional_expression){
   statement1;
}
else if(conditional_expression){
   statement2;
}
else if(conditional_expression){
   statement3;
}
else if(conditional_expression){
   statement4;
}
else{
   statement5;
}

Example C Program for Nested if statement

#include <stdio.h>
#include <conio.h>

int main()
{
	int A=20;
	int B=15;
	if (A < B){
		printf("The A value is less than B \n");
	}
	else if (A > 100){
		printf("The A value is greater than 100 \n");
	}
	else if (A == B){
		printf("The A value is equal to B \n");
	}
	else {
		printf("The A value is neither less than B nor greater than 100, It is also not equal to B \n");
	}

	printf("The A value is: %d ",A);
	return(0)
}

Output

The A value is neither less than B nor greater than 100, It is also not equal to B
The A value is:20

<< Previous

Next >>







C - if else if ladder Control Statements

<<Previous

Next >>





if else if

By using if else if ladder, we can test the multiple condition. Here the conditional expressions are evaluated in order. If the condition is true, then that particular statement will be executed. Suppose if none of the condition is true, then default else statement will be executed.

Syntax:

if(conditional_expression){
   statement1;
}
else if(conditional_expression){
   statement2;
}
else if(conditional_expression){
   statement3;
}
else if(conditional_expression){
   statement4;
}
else{
   statement5;
}

Example C Program for Nested if statement

#include <stdio.h>
#include <conio.h>

int main()
{
	int A=20;
	int B=15;
	if (A < B){
		printf("The A value is less than B \n");
	}
	else if (A > 100){
		printf("The A value is greater than 100 \n");
	}
	else if (A == B){
		printf("The A value is equal to B \n");
	}
	else {
		printf("The A value is neither less than B nor greater than 100, It is also not equal to B \n");
	}

	printf("The A value is: %d ",A);
	return(0)
}

Output

The A value is neither less than B nor greater than 100, It is also not equal to B
The A value is:20

<< Previous

Next >>







Learn about Hashing and Hash table

Learn Expression Tree

OS Kernel Architecture

OS Arcitecture of Windows, Linux and MacOS

Learn OS scheduling Algorithms