Home » Syntax References

if else if (ladder if) statement syntax in C/C++ language

Syntax of if else if (ladder if) statement in C/C++ programming language, this article contains syntax, examples and explanation about the if else if (ladder if) statement in C language.

Here, is the syntax of if else if (ladder if) statement in C or C++ programming language:

else if(test_condition2)
	//statement(s)/else block;

This is a form of if else statement, where we can check multiple test conditions it is also known as multiple if else statement, it checks test conditions one by one.

If test_condition1 is true then block1 will be executed, if it is false then test_condition2 will be checked, if test_condition2 is true then block2 will be executed, if it is false then next condition will be checked.

If any of the test conditions is not true then else block will be executed.

Consider the given example:

#include <stdio.h>

int main()
	int a=-20;
		printf("%d is a postive integer\n",a);
	else if(a<0)
		printf("%d is a negative integer\n",a);
		printf("Its ZERO\n");
	return 0;	


-20 is a negative integer

In this program, the value of a is -20, so first condition (a>0) is false and then second condition (a<0) is true. Thus, "-20 is a negative integer" is printed.

Comments and Discussions

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.