The If... Else If... Else Statement
The If... Else If... Else Statement
When using if , else if , else statements there are few points to keep in
mind.
An if can have zero or one else's and it must come after any else if's.
An if can have zero to many else if's and they must come before the else.
Once an else if succeeds, none of he remaining else if's or else's will be tested.
Syntax:
The syntax of an if...else if...else statement in C++ is:
if(boolean_expression 1)
else
}
#include <iostream>
int main ()
int a = 100;
if( a < 20 )
else
return 0;
#include <iostream>
int main ()
int a = 100;
// check the boolean condition
if( a == 10 )
else if( a == 20 )
else if( a == 30 )
else
return 0;
When the above code is compiled and executed, it produces the following
result: