- If else statement is considered as part of an if statement.
- But else block and add to it.
- The statement given in Else block is executed when the condition of if is false.
if(condition)
{
/* Statements to be executed when condition is true */
}
else
{
/* Statements to be executed when condition is false */
}
- As you know if the statements in if block are executed on if the condition is true.
- But you can also decide what to do if the condition is false.
- For this you use else block. This block always comes after the if block.
- These statements are written in this block, which will be executed if the condition is false.
- If if else statement is used in the above example then you can write it like this.
#include <stdio.h>
void main()
{
int sudoAge = 25;
int bkAge = 30;
/* Taking decision using if else statements */
if(sudoAge > bkAge)
{
printf("Sudo is elder:");
}
else
{
printf("Bk is elder:");
}
}
OUTPUT
Bk is elder:
No comments:
Post a Comment
Please do not any spam link in Comment Box