C else...if Statement
C else...if Statement
The else...if
statement executes a block if the specified condition is true. This occurs only when the preceeding condition in the if
or else if
failed.
Note: You can use multiple else if statement one after the other.
The following 2 example programs will help you to understand the if statement better.
Single else...if Statement
In the below example program, the else...if
block will be executed because the value in the variable x
is lesser than 50 but greater than 20.
Source Code
Output
Multiple else...if Statement
In the below example program, the value in a variable x is 12.
- First,
if
condition checks whether x > 50 and returns false. - Second,
else...if
condition checks whether x > 20 and returns false. - Third,
else...if
condition checks whether x > 10 and returns true and executes the block of code. - Fourth,
else
block is skipped as we have true condition.
Source Code
Output
Congratulation! you have learned everything about else...if
statement in C Programming.
Reminder
Hi Developers, we almost covered 98% of String functions and Interview Question on C with examples for quick and easy learning.
We are working to cover every Single Concept in C.
Please do google search for:
Join Our Channel
Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.
This channel is primarily useful for Full Stack Web Developer.