if….else Statement
Decision making are needed when, the program
encounters the situation to choose a particular statement among many
statements. C programming provides following statements to make decision
makings:
·
if…else statement
·
switch statement
if(test
expression)
statements to be executed if test
expression is true;
Nested if…else statement (if…else
Statement)
The if…else statement can be used in nested
form when a serious decision are involved. The ANSI standard specifies that 15
levels of nesting may be continued.
Syntax of nested if…else
Statement:
if(test
expression)
statement to be executed if test expression
is true;
else
if(test expression 1)
statements to be executed if test expression
1 is true;
else if
.
.
.
else
statements to be executed if all test
expressions are false;
How nested if…else works?
If the test expression is true, it will execute
the relevant code but, if it is false, the control of the program jumps to the
else part and check test expression 1 and the process continues. If all the
test expressions are false then, only the last statement is executed.
No comments:
Post a Comment