CH 13
CH 13
Decision Structures
Need for Decision Structures in C:-
Most of the C programs presented the sequential structure ( mean instructions are executed one by one)
in a program.
◦ But sometime, we may want to execute some of the statements based on some conditions. For that, it
is required to change the flow of the sequence of instructions.
▪ C language provides facility through special kind of statements that can change the flow of a
sequence of instructions in the program. Such statements are called decision structure
statements,
Decision structure statements help us to jump from one part of the program to another part of program
based on result of some conditions.
Sometimes decision structure statements are also known as selective structures statements, branching
statements or decision making statements.
As these statements are controlling the flow of execution, they are also known as control statements.
The if Statement:-
, can be used to transfer control of instruction execution.
◦ The if statement can be used in following different ways:
1. Simple if statement
2. if-else statement
3. nested if statement and
4. else-if ladder statement
Simple if statement:-
It is the simplest form of the if statement.
It is frequently used in the program for decision making and allowing us to change the flow of program
execution.
( The syntax says if the test expression is true then executes the statement-block and if the test expression
is false then computer skips the statement-block and executes the next instruction of the program.
C programming language assumes any non-zero and non-null values as true and if it is either zero or
null then it is assumed as false value. )