Control Structure
Types of Control Structure
Control structure
• A statement used to control the flow of
execution in a program is called control
structure.
Types of Control Structure
• 1 . Sequence structure
• 2 . Selection structure
• 3 . Repetition structure
Sequence structure
• In sequence structure, the statements are
executed in the same order in which they are
specified in program. The control flow from
one statement to other in a logical sequence.
All statement are executed exactly once. It
means that no statement is skipped and no
statement is executed more then once.
Sequence structure
Sequence structure
Write a program that adds two number and shows the sum.
#include <iostream.h>
#include <conio.h>
Void main()
{
int var1,var2,sum;
var1=30;
var2=20;
sum =var1+var2;
cout<<sum;
getch();
Selection Structure
• A selection structure selects a statement or
set of statements to execute on the basis of a
condition. In this structure, statement or set
of statements is executed when a particular
condition is true and ignored when the
condition is false.
Selection Structure
• There are different types selection structure in
c++.
• These are if , if……else, and switch.
Selection Structure
Selection Structure
Write a program that inputs marks and display “pass” if the
marks are 40 or more.
#include <iostream.h>
#include <conio.h>
Void main()
{
int marks;
cout<<“Enter your marks”;
cin>>marks;
If (marks>=40)
cout<<“pass”;
getch();
Repetition Structure
• A repetition structure executes a statement or
set of statements repeatedly. It is also known
as iteration structure or loop.
Repetition Structure
• There are different types of repetition
structure in c++.
• These are while, do-while and for.
Repetition Structure
Repetition Structure
Write a program that displays counting 1 to 5 using for loop.
#include <iostream.h>
#include <conio.h>
Void main()
{
int n;
for(n=1;n<=5;n++)
cout<<n;
getch();