SlideShare a Scribd company logo
C++ Language
By:-AAKASH KAUSHIK
#9289817971, 98919893083
Email-theaakashkumar@gmail.com
UNIT -5
FLOW OF CONTROL
FLOW OF CONTROL
IT REFERS TO THE FLOW IN WHICH A
PROGRAM EXECUTION TAKES PLACE.
AAKASH KAUSHIK
9891983083,9289817971
FLOW OF CONTROL
1.)Sequential
IN this each statement of a program is executed
sequentially i.e, one after another
2.)Conditional/Decision Making
3.)Iterations/Looping
AAKASH KAUSHIK
9891983083,9289817971
CONDITIONS
IF
IF-ELSE
ELSE IF LADDER
NESTED IF
SWITCH
CONDITIONAL OPERATOR
TYPE OF CONDITIONS
AAKASH KAUSHIK
9891983083,9289817971
It takes a condition in parenthesis and a code block .If
the condition will results into true the code block will
execute or if the condition will false the code block will
be skipped.
The general form of a simple if statement is
if (test expression)
{
statement-block;
}
statement-x;
IF CONDITION
AAKASH KAUSHIK
9891983083,9289817971
It is the extension of simple if statement. It contains an
additional else block also. If the condition will results into
true the if code block will execute or if the condition will
false the else code block will execute.
if (test expression)
{
True-block statement(s)
}
else
{
False-block statement(s)
}
statement-x
IF ELSE CONDITION
AAKASH KAUSHIK
9891983083,9289817971
EXAMPLE
#include<iostream.h>
#include<conio.h>
void main()
{
int num;
cout<<"Enter any number : ";
cin>>num;
if(num>0)
cout<<num<<" is Positive.";
else
cout<<num<<" is Negative.";
}
AAKASH KAUSHIK
9891983083,9289817971
There is another way of putting ifs together when
multiple decisions are involved. A multipath decision
is a chain of ifs in which the statement associated
with each else is an if. It takes the following general
form:
if (condition 1)
statement 1 ;
else if (condition 2)
statement 2;
else if (condition n)
statement n;
else
default statement;
statement x;
THE ELSE IF LADDER
AAKASH KAUSHIK
9891983083,9289817971
If the condition-1 is true statement-1 will be
executed; otherwise it continues to perform the
other test condition-2 then condition-3 and so on
Until any condition results into true otherwise by
default else block i.e, default-statement will get
executed and control will be transferred to
statement –X.
The else block is Optional and Default.
THE ELSE IF LADDER
AAKASH KAUSHIK
9891983083,9289817971
EXAMPLE
#include<iostream.h>
#include<conio.h>
void main()
{
int amt,discount;
cout<<"Enter amount : ";
cin>>amt;
if(amt>20000)
discount=15;
else if(amt>15000)
discount=10;
else if(amt>10000)
discount=5;
else discount=0;
cout<<"You will get "<<discount<<"% discount.";
}
Nested if also known as if within if or
condition within condition. When a series
of decisions are involved, we may have to
use more than one if...else statements in
nested form i.e., body of an if or else part
will also be a condition(if..else).
NESTED IF
AAKASH KAUSHIK
9891983083,9289817971
if (test condition1)
{
if (test condition 2)
{
statement-1;
}
else
{
statement-2;
}
}
else
{
statement-3;
}
statement-x;
NESTED IF
AAKASH KAUSHIK
9891983083,9289817971
If condition-1 will true
then its body will execute
and condition-2 is tested
if it will true statement-1
will execute otherwise
statement-2 will execute
or if condition-1 will false
then as a result
statement-3 will execute
and in all the cases
control will be transferred
to statement-X.
AAKASH KAUSHIK
9891983083,9289817971
EXAMPLE
#include<iostream.h>
#include<conio.h>
void main()
{
int a,b,c;
cout<<"nEnter value of A ,B,C ";
cin>>a>>b>>c;
if(a>b)
{
if(a>c)
cout<<"nnA is Greatest";
else
cout<<"nnC is Greatest";
}
else
{
if(b>c)
cout<<"nnB is Greatest";
else
cout<<"nnC is Greatest";
}
}
C++ Provides a multiple-branch selection
statement known as SWITCH. This selection
statement tests the value of an expression against
a list of integer or character constants. When a
match is found, the statement associated with that
constant are executed if no match is found then
the default statement gets executed.
THE SWITCH STATEMENT
AAKASH KAUSHIK
9891983083,9289817971
switch(expression)
{
case constant 1: statement sequence 1;
break;
case constant 2: statement sequence 2;
break;
case constant 3: statement sequence 3;
break;
case constant n-1: statement sequence n-1;
break;
default : statement sequence n;
}
//default statement is optional
SYNTAX:-
AAKASH KAUSHIK
9891983083,9289817971
AAKASH KAUSHIK
9891983083,9289817971
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int dow;
cout<<"Enter weekday number(1-7)";
cin>>dow;
switch(dow)
{
case 1:cout<<"MONDAY";
break;
case 2:cout<<"TUESDAY";
break;
case 3:cout<<"WEDNESDAY";
break;
case 4:cout<<"THURSDAY";
break;
case 5:cout<<"FRIDAY";
break;
case 6:cout<<"SATURDAY";
break;
case 7:cout<<"SUNDAY";
break;
default:cout<<"wrong number of day";
break;
}
getch();
}
Example of switch
The break statement used under switch is one of
C++ jump statements . whenever a case
constant is matched with expression in the
switch that particular part starts execution and
lasts until any break statement is encountered or
until the end of switch. Due to break statements
the program execution jumps to line following
the switch i.e., outside the body of the switch
statement otherwise it will execute all the
statements following the matched case in the
switch.
Usage of break in switch
AAKASH KAUSHIK
9891983083,9289817971
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int num;
cout<<“enter any num”;
cin>>num;
switch(num)
{
case 1:cout<<“Onen”;
case 2:cout<<“Twon”;
break;
case 3:cout<<“Threen”;
case 4:cout<<“Fourn”;
break;
default:cout<<“wrong entry”;
}
getch();
}
Example of Usage of break in switch
Switch v/s if-else..
If else..
It can handle logical or
relational expressions i.e.,
multiple conditions.
If else is more versatile
as it can handle ranges.
If else can work upon int
, char & floating point
data also.
If else construction lets
you use a series of
expressions that may
involve unrelated
variables
Switch
Switch can only test for
equality
Switch case label must be
only a single value.
Switch works only with
int & char data types.
The switch statement
selects its branches by
testing the value of same
variable(against a set of
constants)
AAKASH KAUSHIK
9891983083,9289817971
Switch v/s if-else..
If else..
It can handle logical or
relational expressions i.e.,
multiple conditions.
If else is more versatile
as it can handle ranges.
If else can work upon int
, char & floating point
data also.
If else construction lets
you use a series of
expressions that may
involve unrelated
variables
Switch
Switch can only test for
equality
Switch case label must be
only a single value.
Switch works only with
int & char data types.
The switch statement
selects its branches by
testing the value of same
variable(against a set of
constants)
AAKASH KAUSHIK
9891983083,9289817971
ITERATIONS/LOOPING
ITERATIONS/LOOPING
AAKASH KAUSHIK
9891983083,9289817971
Same block/set of statements is
executed repeatedly (again & again)
until a specific condition is fulfilled.
PARTS OF LOOP
AAKASH KAUSHIK
9891983083,9289817971
1.)Initialization Expression- It is the initialization
Statement of the Control variable( variable used to
control the loop) .i.e., The value from which loop will
start it’s execution
2.)Test Expression/Condition - the condition up to which
loop will keep on execution. If the condition results true
loop-body will execute again otherwise the loop is
terminated
3.)Updation- the loop variable is incremented or
decremented according to the needs for which the next
iteration will be performed.
4.)Body of loop- Code Block/Statements need to be
executed repeatedly until the conditions results true.
FOR loop
WHILE loop
Do-WHILE loop
Nested loops
Type of LOOPS
AAKASH KAUSHIK
9891983083,9289817971
Syntax:-
for(intializtion ; condition ; updation)
{
- - - - -
- - - - -
- - - - -
}
FOR LOOP
AAKASH KAUSHIK
9891983083,9289817971
BODY OF LOOP
FOR LOOP EXECUTION SEQUENCE
AAKASH KAUSHIK
9891983083,9289817971
INTIALIZATION
CONDITION
CHECKING
TERMINATE
LOOP
BODY
EXECUTION UPDATION
FALSE
T
R
U
E
START
Syntax:-
Initialization
While(condition)
{
- - - - -
- - - - -
- - - - -
}
WHILE LOOP
AAKASH KAUSHIK
9891983083,9289817971
BODY OF LOOP
+
UPDATION
WHILE LOOP EXECUTION SEQUENCE
AAKASH KAUSHIK
9891983083,9289817971
INTIALIZATION
CONDITION
CHECKING
TERMINATE
LOOPFALSE
T
R
U
E
START
BODY
EXECUTION
+
UPDATION
Syntax:-
Initialization
do
{
- - - - -
- - - - -
- - - - -
}
While(condition)
DO WHILE LOOP
AAKASH KAUSHIK
9891983083,9289817971
BODY OF LOOP
+
UPDATION
DO-WHILE LOOP EXECUTION SEQUENCE
AAKASH KAUSHIK
9891983083,9289817971
INTIALIZATION
BODY
EXECUTION
+
UPDATION
CONDITION
CHECKING
START
TERMINATE
LOOP
F
A
L
S
E
T
R U E
THANK
YOU
AAKASH KAUSHIK
9891983083,9289817971

More Related Content

What's hot

C++ classes tutorials
C++ classes tutorialsC++ classes tutorials
C++ classes tutorials
Mayank Jain
 
Strings in c++
Strings in c++Strings in c++
Strings in c++
Neeru Mittal
 
Inline function in C++
Inline function in C++Inline function in C++
Inline function in C++
Learn By Watch
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
Paumil Patel
 
C programming language tutorial
C programming language tutorial C programming language tutorial
C programming language tutorial
javaTpoint s
 
Control flow statements in java
Control flow statements in javaControl flow statements in java
Control flow statements in java
yugandhar vadlamudi
 
Control Structure in C
Control Structure in CControl Structure in C
Control Structure in C
Neel Shah
 
Control structures in java
Control structures in javaControl structures in java
Control structures in java
VINOTH R
 
If else statement in c++
If else statement in c++If else statement in c++
If else statement in c++
Bishal Sharma
 
Program control statements in c#
Program control statements in c#Program control statements in c#
Program control statements in c#
Dr.Neeraj Kumar Pandey
 
Looping statements
Looping statementsLooping statements
Looping statements
Jaya Kumari
 
Control structure
Control structureControl structure
Control structure
Samsil Arefin
 
Basic array in c programming
Basic array in c programmingBasic array in c programming
Basic array in c programming
Sajid Hasan
 
Decision Making Statement in C ppt
Decision Making Statement in C pptDecision Making Statement in C ppt
Decision Making Statement in C ppt
MANJUTRIPATHI7
 
If statements in c programming
If statements in c programmingIf statements in c programming
If statements in c programming
Archana Gopinath
 
Storage classes in C
Storage classes in CStorage classes in C
Storage classes in C
Nitesh Bichwani
 
C Programming: Control Structure
C Programming: Control StructureC Programming: Control Structure
C Programming: Control Structure
Sokngim Sa
 
Data types in c++
Data types in c++Data types in c++
Data types in c++
Venkata.Manish Reddy
 
Decision making and looping
Decision making and loopingDecision making and looping
Decision making and looping
Hossain Md Shakhawat
 
C++ Pointers And References
C++ Pointers And ReferencesC++ Pointers And References
C++ Pointers And Referencesverisan
 

What's hot (20)

C++ classes tutorials
C++ classes tutorialsC++ classes tutorials
C++ classes tutorials
 
Strings in c++
Strings in c++Strings in c++
Strings in c++
 
Inline function in C++
Inline function in C++Inline function in C++
Inline function in C++
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
 
C programming language tutorial
C programming language tutorial C programming language tutorial
C programming language tutorial
 
Control flow statements in java
Control flow statements in javaControl flow statements in java
Control flow statements in java
 
Control Structure in C
Control Structure in CControl Structure in C
Control Structure in C
 
Control structures in java
Control structures in javaControl structures in java
Control structures in java
 
If else statement in c++
If else statement in c++If else statement in c++
If else statement in c++
 
Program control statements in c#
Program control statements in c#Program control statements in c#
Program control statements in c#
 
Looping statements
Looping statementsLooping statements
Looping statements
 
Control structure
Control structureControl structure
Control structure
 
Basic array in c programming
Basic array in c programmingBasic array in c programming
Basic array in c programming
 
Decision Making Statement in C ppt
Decision Making Statement in C pptDecision Making Statement in C ppt
Decision Making Statement in C ppt
 
If statements in c programming
If statements in c programmingIf statements in c programming
If statements in c programming
 
Storage classes in C
Storage classes in CStorage classes in C
Storage classes in C
 
C Programming: Control Structure
C Programming: Control StructureC Programming: Control Structure
C Programming: Control Structure
 
Data types in c++
Data types in c++Data types in c++
Data types in c++
 
Decision making and looping
Decision making and loopingDecision making and looping
Decision making and looping
 
C++ Pointers And References
C++ Pointers And ReferencesC++ Pointers And References
C++ Pointers And References
 

Similar to C++ programming Unit 5 flow of control

CONTROL STMTS.pptx
CONTROL STMTS.pptxCONTROL STMTS.pptx
CONTROL STMTS.pptx
JavvajiVenkat
 
C statements
C statementsC statements
C statements
Ahsann111
 
Lect3-C--EEB.pptx
Lect3-C--EEB.pptxLect3-C--EEB.pptx
Lect3-C--EEB.pptx
KIJAMALEGI
 
Introduction to Selection control structures in C++
Introduction to Selection control structures in C++ Introduction to Selection control structures in C++
Introduction to Selection control structures in C++
Neeru Mittal
 
C-Programming Control statements.pptx
C-Programming Control statements.pptxC-Programming Control statements.pptx
C-Programming Control statements.pptx
SKUP1
 
C-Programming Control statements.pptx
C-Programming Control statements.pptxC-Programming Control statements.pptx
C-Programming Control statements.pptx
LECO9
 
Module 2- Control Structures
Module 2- Control StructuresModule 2- Control Structures
Module 2- Control Structures
nikshaikh786
 
c++ programming Unit 3 variables,data types
c++ programming Unit 3 variables,data typesc++ programming Unit 3 variables,data types
c++ programming Unit 3 variables,data types
AAKASH KUMAR
 
Controls & Loops in C
Controls & Loops in C Controls & Loops in C
Controls & Loops in C
Thesis Scientist Private Limited
 
Control Statement.ppt
Control Statement.pptControl Statement.ppt
Control Statement.ppt
sanjay
 
Lecture 5
Lecture 5Lecture 5
Lecture 5
Mohammed Khan
 
Loops and iteration.docx
Loops and iteration.docxLoops and iteration.docx
Loops and iteration.docx
NkurikiyimanaGodefre
 
[ITP - Lecture 11] Loops in C/C++
[ITP - Lecture 11] Loops in C/C++[ITP - Lecture 11] Loops in C/C++
[ITP - Lecture 11] Loops in C/C++
Muhammad Hammad Waseem
 
Selection Statements in C Programming
Selection Statements in C ProgrammingSelection Statements in C Programming
Selection Statements in C Programming
Kamal Acharya
 
Repetition loop
Repetition loopRepetition loop
Repetition loop
Adnan Rana
 
Loop and while Loop
Loop and while LoopLoop and while Loop
Loop and while Loop
JayBhavsar68
 
Loops
LoopsLoops

Similar to C++ programming Unit 5 flow of control (20)

CONTROL STMTS.pptx
CONTROL STMTS.pptxCONTROL STMTS.pptx
CONTROL STMTS.pptx
 
C statements
C statementsC statements
C statements
 
Lect3-C--EEB.pptx
Lect3-C--EEB.pptxLect3-C--EEB.pptx
Lect3-C--EEB.pptx
 
Introduction to Selection control structures in C++
Introduction to Selection control structures in C++ Introduction to Selection control structures in C++
Introduction to Selection control structures in C++
 
C-Programming Control statements.pptx
C-Programming Control statements.pptxC-Programming Control statements.pptx
C-Programming Control statements.pptx
 
C-Programming Control statements.pptx
C-Programming Control statements.pptxC-Programming Control statements.pptx
C-Programming Control statements.pptx
 
Module 2- Control Structures
Module 2- Control StructuresModule 2- Control Structures
Module 2- Control Structures
 
c++ programming Unit 3 variables,data types
c++ programming Unit 3 variables,data typesc++ programming Unit 3 variables,data types
c++ programming Unit 3 variables,data types
 
Controls & Loops in C
Controls & Loops in C Controls & Loops in C
Controls & Loops in C
 
Control Statement.ppt
Control Statement.pptControl Statement.ppt
Control Statement.ppt
 
Lecture 5
Lecture 5Lecture 5
Lecture 5
 
Loops and iteration.docx
Loops and iteration.docxLoops and iteration.docx
Loops and iteration.docx
 
[ITP - Lecture 11] Loops in C/C++
[ITP - Lecture 11] Loops in C/C++[ITP - Lecture 11] Loops in C/C++
[ITP - Lecture 11] Loops in C/C++
 
Chap 6(decision making-looping)
Chap 6(decision making-looping)Chap 6(decision making-looping)
Chap 6(decision making-looping)
 
Selection Statements in C Programming
Selection Statements in C ProgrammingSelection Statements in C Programming
Selection Statements in C Programming
 
Repetition loop
Repetition loopRepetition loop
Repetition loop
 
M C6java6
M C6java6M C6java6
M C6java6
 
Control statement in c
Control statement in cControl statement in c
Control statement in c
 
Loop and while Loop
Loop and while LoopLoop and while Loop
Loop and while Loop
 
Loops
LoopsLoops
Loops
 

More from AAKASH KUMAR

NETWORKING AND COMMUNICATION || SLIDE 1 || TOPOLOGY AND PLACEMENT OF DEVICES|...
NETWORKING AND COMMUNICATION || SLIDE 1 || TOPOLOGY AND PLACEMENT OF DEVICES|...NETWORKING AND COMMUNICATION || SLIDE 1 || TOPOLOGY AND PLACEMENT OF DEVICES|...
NETWORKING AND COMMUNICATION || SLIDE 1 || TOPOLOGY AND PLACEMENT OF DEVICES|...
AAKASH KUMAR
 
2 d array(part 2) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS
2 d array(part 2) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS2 d array(part 2) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS
2 d array(part 2) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS
AAKASH KUMAR
 
Inheritance question
Inheritance questionInheritance question
Inheritance question
AAKASH KUMAR
 
Header file BASED QUESTION- CBSE CS CLASS 12TH
Header file BASED QUESTION- CBSE CS CLASS 12THHeader file BASED QUESTION- CBSE CS CLASS 12TH
Header file BASED QUESTION- CBSE CS CLASS 12TH
AAKASH KUMAR
 
Constructor & destructor based question- cbse cs class 12th
Constructor & destructor based question-  cbse cs class 12thConstructor & destructor based question-  cbse cs class 12th
Constructor & destructor based question- cbse cs class 12th
AAKASH KUMAR
 
CHOOSE THE CORRECT IDENTIFIER - Q.1 CBSE CS EXAM
CHOOSE THE CORRECT IDENTIFIER - Q.1 CBSE CS EXAMCHOOSE THE CORRECT IDENTIFIER - Q.1 CBSE CS EXAM
CHOOSE THE CORRECT IDENTIFIER - Q.1 CBSE CS EXAM
AAKASH KUMAR
 
Practical exam special- CBSE CS CLASS 12th
Practical exam special- CBSE CS CLASS 12thPractical exam special- CBSE CS CLASS 12th
Practical exam special- CBSE CS CLASS 12th
AAKASH KUMAR
 
2 d array(part 1) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS
2 d array(part 1) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS2 d array(part 1) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS
2 d array(part 1) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS
AAKASH KUMAR
 
STACK || FUNCTION WRITING BASED ON STACK || DATA STRUCTURE || LINKED LIST || ...
STACK || FUNCTION WRITING BASED ON STACK || DATA STRUCTURE || LINKED LIST || ...STACK || FUNCTION WRITING BASED ON STACK || DATA STRUCTURE || LINKED LIST || ...
STACK || FUNCTION WRITING BASED ON STACK || DATA STRUCTURE || LINKED LIST || ...
AAKASH KUMAR
 
QUEUE || FUNCTION WRITING BASED ON QUEUE || LINKED LIST || DATA STRUCTURE || ...
QUEUE || FUNCTION WRITING BASED ON QUEUE || LINKED LIST || DATA STRUCTURE || ...QUEUE || FUNCTION WRITING BASED ON QUEUE || LINKED LIST || DATA STRUCTURE || ...
QUEUE || FUNCTION WRITING BASED ON QUEUE || LINKED LIST || DATA STRUCTURE || ...
AAKASH KUMAR
 
Inheritance question class 12th
Inheritance question class 12thInheritance question class 12th
Inheritance question class 12th
AAKASH KUMAR
 
Ms word Part 2
Ms  word Part 2Ms  word Part 2
Ms word Part 2
AAKASH KUMAR
 
Ms word Part 1
Ms  word Part 1Ms  word Part 1
Ms word Part 1
AAKASH KUMAR
 
Power point2007instruction
Power point2007instructionPower point2007instruction
Power point2007instruction
AAKASH KUMAR
 
Html introduction Part-2
Html introduction Part-2Html introduction Part-2
Html introduction Part-2
AAKASH KUMAR
 
Html Slide Part-1
Html Slide Part-1Html Slide Part-1
Html Slide Part-1
AAKASH KUMAR
 
Evolution / history of Computer
Evolution / history of ComputerEvolution / history of Computer
Evolution / history of Computer
AAKASH KUMAR
 
computer system
computer system computer system
computer system
AAKASH KUMAR
 
Array within a class
Array within a classArray within a class
Array within a class
AAKASH KUMAR
 
Input Output Devices and Memory Unit
Input Output Devices and Memory UnitInput Output Devices and Memory Unit
Input Output Devices and Memory Unit
AAKASH KUMAR
 

More from AAKASH KUMAR (20)

NETWORKING AND COMMUNICATION || SLIDE 1 || TOPOLOGY AND PLACEMENT OF DEVICES|...
NETWORKING AND COMMUNICATION || SLIDE 1 || TOPOLOGY AND PLACEMENT OF DEVICES|...NETWORKING AND COMMUNICATION || SLIDE 1 || TOPOLOGY AND PLACEMENT OF DEVICES|...
NETWORKING AND COMMUNICATION || SLIDE 1 || TOPOLOGY AND PLACEMENT OF DEVICES|...
 
2 d array(part 2) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS
2 d array(part 2) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS2 d array(part 2) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS
2 d array(part 2) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS
 
Inheritance question
Inheritance questionInheritance question
Inheritance question
 
Header file BASED QUESTION- CBSE CS CLASS 12TH
Header file BASED QUESTION- CBSE CS CLASS 12THHeader file BASED QUESTION- CBSE CS CLASS 12TH
Header file BASED QUESTION- CBSE CS CLASS 12TH
 
Constructor & destructor based question- cbse cs class 12th
Constructor & destructor based question-  cbse cs class 12thConstructor & destructor based question-  cbse cs class 12th
Constructor & destructor based question- cbse cs class 12th
 
CHOOSE THE CORRECT IDENTIFIER - Q.1 CBSE CS EXAM
CHOOSE THE CORRECT IDENTIFIER - Q.1 CBSE CS EXAMCHOOSE THE CORRECT IDENTIFIER - Q.1 CBSE CS EXAM
CHOOSE THE CORRECT IDENTIFIER - Q.1 CBSE CS EXAM
 
Practical exam special- CBSE CS CLASS 12th
Practical exam special- CBSE CS CLASS 12thPractical exam special- CBSE CS CLASS 12th
Practical exam special- CBSE CS CLASS 12th
 
2 d array(part 1) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS
2 d array(part 1) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS2 d array(part 1) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS
2 d array(part 1) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS
 
STACK || FUNCTION WRITING BASED ON STACK || DATA STRUCTURE || LINKED LIST || ...
STACK || FUNCTION WRITING BASED ON STACK || DATA STRUCTURE || LINKED LIST || ...STACK || FUNCTION WRITING BASED ON STACK || DATA STRUCTURE || LINKED LIST || ...
STACK || FUNCTION WRITING BASED ON STACK || DATA STRUCTURE || LINKED LIST || ...
 
QUEUE || FUNCTION WRITING BASED ON QUEUE || LINKED LIST || DATA STRUCTURE || ...
QUEUE || FUNCTION WRITING BASED ON QUEUE || LINKED LIST || DATA STRUCTURE || ...QUEUE || FUNCTION WRITING BASED ON QUEUE || LINKED LIST || DATA STRUCTURE || ...
QUEUE || FUNCTION WRITING BASED ON QUEUE || LINKED LIST || DATA STRUCTURE || ...
 
Inheritance question class 12th
Inheritance question class 12thInheritance question class 12th
Inheritance question class 12th
 
Ms word Part 2
Ms  word Part 2Ms  word Part 2
Ms word Part 2
 
Ms word Part 1
Ms  word Part 1Ms  word Part 1
Ms word Part 1
 
Power point2007instruction
Power point2007instructionPower point2007instruction
Power point2007instruction
 
Html introduction Part-2
Html introduction Part-2Html introduction Part-2
Html introduction Part-2
 
Html Slide Part-1
Html Slide Part-1Html Slide Part-1
Html Slide Part-1
 
Evolution / history of Computer
Evolution / history of ComputerEvolution / history of Computer
Evolution / history of Computer
 
computer system
computer system computer system
computer system
 
Array within a class
Array within a classArray within a class
Array within a class
 
Input Output Devices and Memory Unit
Input Output Devices and Memory UnitInput Output Devices and Memory Unit
Input Output Devices and Memory Unit
 

Recently uploaded

Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
Advantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO PerspectiveAdvantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO Perspective
Krisztián Száraz
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
Marketing internship report file for MBA
Marketing internship report file for MBAMarketing internship report file for MBA
Marketing internship report file for MBA
gb193092
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 
Normal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of LabourNormal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of Labour
Wasim Ak
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdfMASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
goswamiyash170123
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
deeptiverma2406
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
Multithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race conditionMultithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race condition
Mohammed Sikander
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 

Recently uploaded (20)

Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
Advantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO PerspectiveAdvantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO Perspective
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
Marketing internship report file for MBA
Marketing internship report file for MBAMarketing internship report file for MBA
Marketing internship report file for MBA
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 
Normal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of LabourNormal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of Labour
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdfMASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
Multithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race conditionMultithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race condition
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 

C++ programming Unit 5 flow of control

  • 1. C++ Language By:-AAKASH KAUSHIK #9289817971, 98919893083 Email-theaakashkumar@gmail.com
  • 2. UNIT -5 FLOW OF CONTROL
  • 3. FLOW OF CONTROL IT REFERS TO THE FLOW IN WHICH A PROGRAM EXECUTION TAKES PLACE. AAKASH KAUSHIK 9891983083,9289817971
  • 4. FLOW OF CONTROL 1.)Sequential IN this each statement of a program is executed sequentially i.e, one after another 2.)Conditional/Decision Making 3.)Iterations/Looping AAKASH KAUSHIK 9891983083,9289817971
  • 6. IF IF-ELSE ELSE IF LADDER NESTED IF SWITCH CONDITIONAL OPERATOR TYPE OF CONDITIONS AAKASH KAUSHIK 9891983083,9289817971
  • 7. It takes a condition in parenthesis and a code block .If the condition will results into true the code block will execute or if the condition will false the code block will be skipped. The general form of a simple if statement is if (test expression) { statement-block; } statement-x; IF CONDITION AAKASH KAUSHIK 9891983083,9289817971
  • 8. It is the extension of simple if statement. It contains an additional else block also. If the condition will results into true the if code block will execute or if the condition will false the else code block will execute. if (test expression) { True-block statement(s) } else { False-block statement(s) } statement-x IF ELSE CONDITION AAKASH KAUSHIK 9891983083,9289817971
  • 9. EXAMPLE #include<iostream.h> #include<conio.h> void main() { int num; cout<<"Enter any number : "; cin>>num; if(num>0) cout<<num<<" is Positive."; else cout<<num<<" is Negative."; } AAKASH KAUSHIK 9891983083,9289817971
  • 10. There is another way of putting ifs together when multiple decisions are involved. A multipath decision is a chain of ifs in which the statement associated with each else is an if. It takes the following general form: if (condition 1) statement 1 ; else if (condition 2) statement 2; else if (condition n) statement n; else default statement; statement x; THE ELSE IF LADDER AAKASH KAUSHIK 9891983083,9289817971
  • 11. If the condition-1 is true statement-1 will be executed; otherwise it continues to perform the other test condition-2 then condition-3 and so on Until any condition results into true otherwise by default else block i.e, default-statement will get executed and control will be transferred to statement –X. The else block is Optional and Default. THE ELSE IF LADDER AAKASH KAUSHIK 9891983083,9289817971
  • 12. EXAMPLE #include<iostream.h> #include<conio.h> void main() { int amt,discount; cout<<"Enter amount : "; cin>>amt; if(amt>20000) discount=15; else if(amt>15000) discount=10; else if(amt>10000) discount=5; else discount=0; cout<<"You will get "<<discount<<"% discount."; }
  • 13. Nested if also known as if within if or condition within condition. When a series of decisions are involved, we may have to use more than one if...else statements in nested form i.e., body of an if or else part will also be a condition(if..else). NESTED IF AAKASH KAUSHIK 9891983083,9289817971
  • 14. if (test condition1) { if (test condition 2) { statement-1; } else { statement-2; } } else { statement-3; } statement-x; NESTED IF AAKASH KAUSHIK 9891983083,9289817971 If condition-1 will true then its body will execute and condition-2 is tested if it will true statement-1 will execute otherwise statement-2 will execute or if condition-1 will false then as a result statement-3 will execute and in all the cases control will be transferred to statement-X.
  • 15. AAKASH KAUSHIK 9891983083,9289817971 EXAMPLE #include<iostream.h> #include<conio.h> void main() { int a,b,c; cout<<"nEnter value of A ,B,C "; cin>>a>>b>>c; if(a>b) { if(a>c) cout<<"nnA is Greatest"; else cout<<"nnC is Greatest"; } else { if(b>c) cout<<"nnB is Greatest"; else cout<<"nnC is Greatest"; } }
  • 16. C++ Provides a multiple-branch selection statement known as SWITCH. This selection statement tests the value of an expression against a list of integer or character constants. When a match is found, the statement associated with that constant are executed if no match is found then the default statement gets executed. THE SWITCH STATEMENT AAKASH KAUSHIK 9891983083,9289817971
  • 17. switch(expression) { case constant 1: statement sequence 1; break; case constant 2: statement sequence 2; break; case constant 3: statement sequence 3; break; case constant n-1: statement sequence n-1; break; default : statement sequence n; } //default statement is optional SYNTAX:- AAKASH KAUSHIK 9891983083,9289817971
  • 18. AAKASH KAUSHIK 9891983083,9289817971 #include<iostream.h> #include<conio.h> void main() { clrscr(); int dow; cout<<"Enter weekday number(1-7)"; cin>>dow; switch(dow) { case 1:cout<<"MONDAY"; break; case 2:cout<<"TUESDAY"; break; case 3:cout<<"WEDNESDAY"; break; case 4:cout<<"THURSDAY"; break; case 5:cout<<"FRIDAY"; break; case 6:cout<<"SATURDAY"; break; case 7:cout<<"SUNDAY"; break; default:cout<<"wrong number of day"; break; } getch(); } Example of switch
  • 19. The break statement used under switch is one of C++ jump statements . whenever a case constant is matched with expression in the switch that particular part starts execution and lasts until any break statement is encountered or until the end of switch. Due to break statements the program execution jumps to line following the switch i.e., outside the body of the switch statement otherwise it will execute all the statements following the matched case in the switch. Usage of break in switch AAKASH KAUSHIK 9891983083,9289817971
  • 20. #include<iostream.h> #include<conio.h> void main() { clrscr(); int num; cout<<“enter any num”; cin>>num; switch(num) { case 1:cout<<“Onen”; case 2:cout<<“Twon”; break; case 3:cout<<“Threen”; case 4:cout<<“Fourn”; break; default:cout<<“wrong entry”; } getch(); } Example of Usage of break in switch
  • 21. Switch v/s if-else.. If else.. It can handle logical or relational expressions i.e., multiple conditions. If else is more versatile as it can handle ranges. If else can work upon int , char & floating point data also. If else construction lets you use a series of expressions that may involve unrelated variables Switch Switch can only test for equality Switch case label must be only a single value. Switch works only with int & char data types. The switch statement selects its branches by testing the value of same variable(against a set of constants) AAKASH KAUSHIK 9891983083,9289817971
  • 22. Switch v/s if-else.. If else.. It can handle logical or relational expressions i.e., multiple conditions. If else is more versatile as it can handle ranges. If else can work upon int , char & floating point data also. If else construction lets you use a series of expressions that may involve unrelated variables Switch Switch can only test for equality Switch case label must be only a single value. Switch works only with int & char data types. The switch statement selects its branches by testing the value of same variable(against a set of constants) AAKASH KAUSHIK 9891983083,9289817971
  • 24. ITERATIONS/LOOPING AAKASH KAUSHIK 9891983083,9289817971 Same block/set of statements is executed repeatedly (again & again) until a specific condition is fulfilled.
  • 25. PARTS OF LOOP AAKASH KAUSHIK 9891983083,9289817971 1.)Initialization Expression- It is the initialization Statement of the Control variable( variable used to control the loop) .i.e., The value from which loop will start it’s execution 2.)Test Expression/Condition - the condition up to which loop will keep on execution. If the condition results true loop-body will execute again otherwise the loop is terminated 3.)Updation- the loop variable is incremented or decremented according to the needs for which the next iteration will be performed. 4.)Body of loop- Code Block/Statements need to be executed repeatedly until the conditions results true.
  • 26. FOR loop WHILE loop Do-WHILE loop Nested loops Type of LOOPS AAKASH KAUSHIK 9891983083,9289817971
  • 27. Syntax:- for(intializtion ; condition ; updation) { - - - - - - - - - - - - - - - } FOR LOOP AAKASH KAUSHIK 9891983083,9289817971 BODY OF LOOP
  • 28. FOR LOOP EXECUTION SEQUENCE AAKASH KAUSHIK 9891983083,9289817971 INTIALIZATION CONDITION CHECKING TERMINATE LOOP BODY EXECUTION UPDATION FALSE T R U E START
  • 29. Syntax:- Initialization While(condition) { - - - - - - - - - - - - - - - } WHILE LOOP AAKASH KAUSHIK 9891983083,9289817971 BODY OF LOOP + UPDATION
  • 30. WHILE LOOP EXECUTION SEQUENCE AAKASH KAUSHIK 9891983083,9289817971 INTIALIZATION CONDITION CHECKING TERMINATE LOOPFALSE T R U E START BODY EXECUTION + UPDATION
  • 31. Syntax:- Initialization do { - - - - - - - - - - - - - - - } While(condition) DO WHILE LOOP AAKASH KAUSHIK 9891983083,9289817971 BODY OF LOOP + UPDATION
  • 32. DO-WHILE LOOP EXECUTION SEQUENCE AAKASH KAUSHIK 9891983083,9289817971 INTIALIZATION BODY EXECUTION + UPDATION CONDITION CHECKING START TERMINATE LOOP F A L S E T R U E