You are on page 1of 11

CONTROL STRUCTURE

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

• Sequential logic is a type of logic circuit whose output depends not only on


the present value of its input signals but on the sequence of past inputs.

• This is the default logic used by every compiler.

• 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

 Also called conditional logic, used to execute a set of instructions


depending over a condition. This logic is also known as branching.

 Branching statements allow the flow of execution to jump to a different part of


the program. The common branching statements used within other control structures
include: 

1: Break 2: Continue 3: Return 4: Go to

 C-Language supports if and switch statements for selection logic. A


conditional operator ?:
Iteration logic

 If a group of instructions is executed repeatedly, until some logical condition has


been satisfied.

 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

 A nested if in C is an if statement that is the target of another if statement.

 Nested if statements means an if statement inside another if statement. Both C and


C++ allows us to nested if statements within if statements i.e., we can place an if
statement inside another if statement.
The Switch 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

You might also like