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

PPTX
Control structures in c++
PPTX
CONDITIONAL STATEMENT IN C LANGUAGE
PPTX
If statements in c programming
PPTX
If else statement in c++
PPTX
Selection statements
PPTX
c++ programming Unit 2 basic structure of a c++ program
PPTX
Fundamental programming structures in java
Control structures in c++
CONDITIONAL STATEMENT IN C LANGUAGE
If statements in c programming
If else statement in c++
Selection statements
c++ programming Unit 2 basic structure of a c++ program
Fundamental programming structures in java

What's hot (20)

PPSX
Break and continue
PPTX
Loops in C
PPTX
PPTX
Exception Handling in object oriented programming using C++
PPTX
Decision making and branching in c programming
PPT
Branching in C
PPTX
Loops c++
PPTX
Unit 1 rules of inference
PPTX
Lecture 2 C++ | Variable Scope, Operators in c++
PDF
SPL 11 | Nested Loops in C
PPT
Basic structure of C++ program
PPTX
Polymorphism in C++
PPTX
Conditionalstatement
PPTX
types of loops and what is loop
PPSX
Exception Handling
PPTX
C++ programming function
PDF
Quadratic programming (Tool of optimization)
PDF
Compiler design lab programs
Break and continue
Loops in C
Exception Handling in object oriented programming using C++
Decision making and branching in c programming
Branching in C
Loops c++
Unit 1 rules of inference
Lecture 2 C++ | Variable Scope, Operators in c++
SPL 11 | Nested Loops in C
Basic structure of C++ program
Polymorphism in C++
Conditionalstatement
types of loops and what is loop
Exception Handling
C++ programming function
Quadratic programming (Tool of optimization)
Compiler design lab programs
Ad

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

PPTX
CONTROL STMTS.pptx
PPTX
C statements
PPT
Flow of Control
PPTX
Control structures
PPT
control-statements, control-statements, control statement
PPTX
Decision Making Statement in C ppt
PPT
2. Control structures with for while and do while.ppt
PPTX
Basic C concepts.
PPTX
Programming in java - Concepts- Operators- Control statements-Expressions
PPTX
Decision makingandbranching in c
PPTX
Mca i pic u-3 handling input output and control statements
PPTX
Btech i pic u-3 handling input output and control statements
PPTX
Bsc cs pic u-3 handling input output and control statements
PPTX
handling input output and control statements
PPTX
C Programming Control Structures(if,if-else)
PDF
PROBLEM SOLVING USING NOW PPSC- UNIT -2.pdf
PDF
Chapter 8 - Conditional Statement
PPTX
C PROGRAMMING-CONTROL STATEMENT (IF-ELSE, SWITCH)
PPTX
Introduction to Selection control structures in C++
PPTX
Diploma ii cfpc u-3 handling input output and control statements
CONTROL STMTS.pptx
C statements
Flow of Control
Control structures
control-statements, control-statements, control statement
Decision Making Statement in C ppt
2. Control structures with for while and do while.ppt
Basic C concepts.
Programming in java - Concepts- Operators- Control statements-Expressions
Decision makingandbranching in c
Mca i pic u-3 handling input output and control statements
Btech i pic u-3 handling input output and control statements
Bsc cs pic u-3 handling input output and control statements
handling input output and control statements
C Programming Control Structures(if,if-else)
PROBLEM SOLVING USING NOW PPSC- UNIT -2.pdf
Chapter 8 - Conditional Statement
C PROGRAMMING-CONTROL STATEMENT (IF-ELSE, SWITCH)
Introduction to Selection control structures in C++
Diploma ii cfpc u-3 handling input output and control statements
Ad

More from AAKASH KUMAR (20)

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

Recently uploaded (20)

PDF
Business Ethics Teaching Materials for college
PDF
TR - Agricultural Crops Production NC III.pdf
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
Complications of Minimal Access Surgery at WLH
PPTX
master seminar digital applications in india
PDF
Microbial disease of the cardiovascular and lymphatic systems
PPTX
Cell Structure & Organelles in detailed.
PPTX
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
PPTX
Cell Types and Its function , kingdom of life
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
PDF
Basic Mud Logging Guide for educational purpose
PDF
RMMM.pdf make it easy to upload and study
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
Business Ethics Teaching Materials for college
TR - Agricultural Crops Production NC III.pdf
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
2.FourierTransform-ShortQuestionswithAnswers.pdf
O5-L3 Freight Transport Ops (International) V1.pdf
Complications of Minimal Access Surgery at WLH
master seminar digital applications in india
Microbial disease of the cardiovascular and lymphatic systems
Cell Structure & Organelles in detailed.
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
Cell Types and Its function , kingdom of life
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
102 student loan defaulters named and shamed – Is someone you know on the list?
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
Basic Mud Logging Guide for educational purpose
RMMM.pdf make it easy to upload and study
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Abdominal Access Techniques with Prof. Dr. R K Mishra

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