0% found this document useful (0 votes)
11 views4 pages

IIIT Bhubaneswar: Dept. Comp. Sc. & Engg. C++ and Object Oriented Programming Flow of Control

The document covers control structures in C++ programming, detailing sequence, selection, and loop structures. It provides examples and syntax for various control statements including if, switch, while, do while, and for loops. Additionally, it emphasizes the concept of structured programming using these control constructs.

Uploaded by

My pat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views4 pages

IIIT Bhubaneswar: Dept. Comp. Sc. & Engg. C++ and Object Oriented Programming Flow of Control

The document covers control structures in C++ programming, detailing sequence, selection, and loop structures. It provides examples and syntax for various control statements including if, switch, while, do while, and for loops. Additionally, it emphasizes the concept of structured programming using these control constructs.

Uploaded by

My pat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

CSE/C++/Module-I/Lecture: 10, 11 1

IIIT Bhubaneswar
Dept. Comp. Sc. & Engg.
C++ and Object Oriented Programming
Lecture: 10, 11

Flow of Control
I. Control structure II. Flow Chart Representation
Lecture: 10:
I. Control Structure:
 While writing a program, sometimes the programmer may require to alter the
flow of execution based on certain condition or to perform the same operation
repeatedly.
 In such situation the programmer uses the control structure.
 A programmer may use one or any combination of the following three control
structure:
 Sequence Structure (straight line)
 Selection Structure (branching)
 Loop Structure (iteration or repetation)

II. Flow Chart Representation:


Entry
True False
Condition
Action 1
True
Action 1 Action 2 Condition Action
Action 2 1
False

Action 3 Exit Action


2
Exit Action 3
[Sequence [Selection Structure ] [Loop Structure]
Structure]

Control

Selection Sequence Loop

If else Switch While, Do while


Case for
2-way branch Multiway branch Entry Control loops
Exit Control loop
NB: The approach of using one or more of these basic control constructs in
programming is known as Structure Programming.
CSE/C++/Module-I/Lecture: 10, 11 2

 Sequence Structure:
Example:
int main()
{
int x, y, sum,avg;
cout<<”Enter the values for x and y”;
cin>>x>>y;
sum=x+y;
avg=sum/2 ;
cout<<”The value of sum is:”<<sum;
cout<<”The value of average is:”<<avg;
return 0;
}
 In this program, the flow of control is sequential from one statement to the
next one.
 Selection Structure:
 In selection structure, the decision making statements are used.
 The if statement
 The if-else statement
 The if-elseif-else statement
 The nested if-else statement
 The switch case statement
 The nested switch case statement
 Along with these we make use of statements like
 break
 continue
 goto

Syntax: Syntax:
I. if statement II. if else statement
if (expression) if (expression)
{ If true { If true
statement1; statement 1;
statement2; } If false
} else
statement; {
... statement 2;
... }
CSE/C++/Module-I/Lecture: 10, 11 3

Syntax: Syntax:
III. if else if statement IV. nested if else statement
if (expression 1) if (expression 1)
{ If true {
statement 1; if (expression 2)
} {
elseif (expression 2) statement 1;
{ If true }
statement 2; else
} {
elseif(expression 3) statement 2;
{ If true }
statement 3; }
} else
else {
{ If false if (expression 3)
statement 4; {
..... statement 3;
} }
else
{
statement 4;
}
}

Syntax:
V. switch case statement
switch (expression)
{ Floating type not allowed (only integer and character t
case 1:
{
statement 1;
....
break;
}
case 2:
{
statement 2;
....
break;
}
default:
statement 3;
}

Lecture: 11:
 Loop Structure:
CSE/C++/Module-I/Lecture: 10, 11 4

 It is broadly divided into two forms:


 Entry Control

While Loop

For loop
 In entry control condition is checked first, if it is true action is performed else
not.
 Exit Control

Do While Loop
 In exit control loops, the condition is checked after the statement is
executed (once), if condition is true then action is repeated else not.

Syntax:
I. The while Loop: If true then it enters the block and executes the statement. Then c
while (condition)
{
statement 1;
statement 2;
.....
}
statement;
...
 If condition is false from the beginning then the block is not executed
at all.
Syntax:
II. The do while Loop:
do
{
statement 1;
statement 2;
.....
} while (condition)
statement;
...
 Execute the block at least once. Then checked the condition.
Syntax:
III. For Loop: 1 2 4
for(initialization; condition; modification)
{
..... When condition is true
statements;
3
.....
}
statements;

You might also like