Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Ch # 11 2nd year computer science notes1
1. DECISION CONSTRUCTS
CHAPTER # 11
SUBJECT: COMPUTER ICS (PART II)
Presented By :
Prof. HASEEB ASLAM
M.Phil. (IT)
( CONCORDIA GROUP OF COLLEGES GUJRANWALA)
1
2. CONTROL STRUCTURE
A statement used to
control the flow of execution in program
is called control structure.
Used to
Combine individual instruction into single logical unit.
Logical Unit has One entry point and
One exit point.
-: Types :-
1. Sequence
2. Selection
3. Repetition
4. Functional Call
2
CONCORDIA
COLLEGE
GUJRANWALA
3. TYPES OF CONTROL STRUCTURE
1. Sequence:-
In sequential structure
Statements are executed in same order.
(in which they are written in program).
Control flows one statement to other in
logical sequence.
All statements are executed only once.
It means
No statement is skipped
No statement is executed more than once 3
ASPIRE
COLLEGE
WAZIRABAD
4. TYPES OF CONTROL STRUCTURE
2. Selection:-
In selection structure selects a statement or set of
statements
are executed on the basis of condition
If condition is true
Statements are executed
If condition is false
Statements are not executed.
-:Types:-
1. If
2. If-else
3. switch 4
ASPIRE
COLLEGE
WAZIRABAD
5. TYPES OF CONTROL STRUCTURE
3. Repetition:-
In repetition structure statement or set of statements
are executed repeatedly.
It is also known as iteration structure or LOOP.
-:Types:-
1. For loop
2. While loop
3. Do-while loop
5
ASPIRE
COLLEGE
WAZIRABAD
6. TYPES OF CONTROL STRUCTURE
4. Functional Call:-
Functional call is a statement that
Moves the control to another block of code.
Control returns back after
Executing all statements in block.
Remaining statements executed immediately
after function call when control is returned.
6
ASPIRE
COLLEGE
WAZIRABAD
7. SELECTION STRUCTURE
A selection statement selects a statement or set of statements
are executed on the basis of condition
If condition is true
Statements are executed
If condition is false
Statements are not executed.
-:Example:-
Suppose program displays Pass
if marks 40 OR more than 40.
It displays fail
if marks are below 40.
Program checks the marks before displaying message.
This process is called decision-making or selection. 7
ASPIRE
COLLEGE
WAZIRABAD
8. TYPES OF SELECTION STRUCTURE
1. If-else Structure:-
It is used to execute or
Skip a statement or set of statements
by using a condition.
2. Switch Structure:-
It is used
• When there are many choices available &
Only one should be executed.
8
ASPIRE
COLLEGE
WAZIRABAD
9. IF STATEMENT / IF STATEMENT WITH ONE
ALTERNATIVE
If is a keyword in c language.
If is decision making statement.
It is simplest form of selection constructs.
It is used to execute or
Skip a statement or set of statements
by checking a condition.
Condition is available in relational expression.
If condition is true
statements are executed.
If condition is false
statements are not executed. 9
ASPIRE
COLLEGE
WAZIRABAD
10. IF STATEMENT / IF STATEMENT WITH ONE
ALTERNATIVE
-:Syntax:-
if ( condition )
statement ;
if (condition )
{
Statements
}
10
ASPIRE
COLLEGE
WAZIRABAD
11. NESTED IF
11
ASPIRE
COLLEGE
WAZIRABAD
if ( condition )
else
{
Statements ;
}
if ( condition )
{
Statements ;
}
else if ( condition )
{
Statements;
}
else
{
Statements;
}
12. NESTED IF
An if statement within
another if statement
is called nested if.
In nested structure
Control enters into inner if
only when outer condition is true.
Only one block is executed
& remaining are skipped automatically.
User can use many if statements
inside another if statement if required.
Increase in level of nesting increases
complexity of nested if statement.
12
ASPIRE
COLLEGE
WAZIRABAD
14. DIFFERENCE B/W
‘ NESTED IF ’ & ‘ IF ’ STATEMENT
An if statement within
another if statement
is called nested if.
In nested structure
Control enters into inner if
only when outer condition is true.
Only one block is executed
& remaining are skipped automatically.
User can use many if statements
inside another if statement if required.
Increase in level of nesting increases
complexity of nested if statement.
14
ASPIRE
COLLEGE
WAZIRABAD