if else statement in C language
It is two way decision making statement. In if else statement, there is only one condition and depending upon the condition, a particular set of statements will be executed.
If condition is true, one set of statements will be executed otherwise another set of statements will be executed
Syntax of simple if statement is:
Condition is any relational or logical expression which will be checked to see whether block of statements specified by “Statement-Block1” will be executed or Statement-Block2 will be executed.
If this condition is true, then Statement-Block1 will be executed.
Otherewise if condition is false Statement-Block2 will be executed.
Statement-Block1 is a set of statements which will be executed if condition is true.
Statement-Block2 is a set of statements which will be executed if condition is false.
Statement-X may be a single statement or group of statements which will be executed in both the cases of condition to be true as well as false.
if else statement can be represented with the help of a flowchart as :
|Program to demonstrate the use of if else statement.|
printf(“\nEnter a number:=”);
printf(“\nnumber is +ve”);
printf(“\nNumber isn’t +ve”);
|Enter a number:= -7|
Number isn’t +ve
Description of Above Program
In the above program, a has been entered -7.
Condition a>0 is false so very next statement after else would be executed i.e. printf(“Number isn’t +ve”) followed by printf(“\nBye”).