Professional Documents
Culture Documents
Group members:
ALI MURTAZA
UMAIR ZAFAR
M.ABDULLAH AYUB
Control Structure And Its TYPES
• A control structure is like a block of programming that analyses variables and chooses a
direction
in which to go based on given parameters. The term flow control details the direction the
program takes. Hence it is the basic decision-making process in computing.
• A computer program is generally composed of three types of structures generally called control
structures. These structures are
• Sequential logic
• Selection logic
• Iteration logic
Sequential logic
• In this logic the program instructions are executed in the order in which
they
appeared in the program.
• The compiler scans the program, instruction by instruction and run the
instruction one by one from top to bottom. This is also called linear logic.
Selection logic
Then the logic is called Iteration logic, repetition logic or looping. C-Language
provides many looping function like while , do-while , and for etc.
The If Statement
The if statement is used to test a condition and then take a possible
action, depending on the condition. This situation can be expressed
using the following block diagram
Figure 1: If statement
The If-else
The if-else is a structure which executes a set of instructions if a
condition is true, otherwise if it is false it executes another set of
statements. This situation can be represented by the following
diagram.
Figure 2: If-Else
The nested if statement
The switch statement causes a particular group of statements to be chosen from several available groups. The
selection is based on the value of expression, which is included in the switch statement.
switch (expression)
{ case value1:
statement_setl;
break;
case value2:
statement--set2;
break;
default: statement_setn;
}
Conditional operator ?:
• Conditional operator can be used instead of if statement. this operator is called ternary
operator because it uses three expressions. Its syntax is
• expressional ? expression_2 : expression_3
• expression_1 is a logical expression which is evaluated first, if it is true then
expression_2 is evaluated and its value becomes the value of whole conditional
expression otherwise expression_3 is evaluated and its value becomes the value of
whole conditional expression. It means out of two expressions either expression_2 or
expression_1 is evaluated. Because expression_1 is a logical expression it must be
enclosed in a pair of brackets ().
.
THANKS