SlideShare a Scribd company logo
1
Chapter 03
2
Loops
3
Outline
• Introduction
• for Loop
• while Loop
• do while Loop
• Nested Loops
• Values of functions and assignment
expressions
• break and continue Statements
4
Introduction
• A loop causes a section of program to be repeated a
certain number of times
• The repetition continues till the condition remains
true: When the condition becomes false the loops
exits and the control passes to the statements
following the loop.
• C++ allows (03) three kinds of loops:
– FOR
– WHILE –
DO … WHILE
for Loop
• The for loop
executes a section
of code a fixed
number of times
• It is usually
(although not
always) used when
it is known in
advance how many
times the code
should be
executed.
j is loop variable
for Loop Operation
Exit Loop
for Loop: Example
for Loop: Exercises
1. Square all numbers from 1 to 10
2. Write a program that generates the following table:
2 x 1 = 2 2 x 2 =
4
2 x 3 = 6
2 x 4 = 8
2 x 5 = 10
3. Print even and odd number from 0 and 1 respectively up to
20
4. Write a program that displays the output:
WHILE Loop
n is loop variable
• A while loop
repeatedly executes a
target statement as
long as a given
condition is true.
WHILE Loop Operation
Exit Loop
WHILE Loop: Example
#include <stdio.h>
#include <conio.h>
int main()
{
int n = 99;
while (n!=0) scanf(“%d”,
&n); getch();
}
DO … WHILE Loop
Unlike FOR and
WHILE loops, which test
the loop condition at the top
of the loop, the DO … WHILE
loop checks its condition at
the bottom of the loop.
The DO … WHILE loop is used
when it is guaranteed that
the loop body will be
executed at least once, even
if the test expression initially
returns false.
DO…WHILE Loop Operation
Exit Loop

More Related Content

What's hot (7)

PPTX
queue
umair khan
 
PPTX
Python project2
Young Song
 
PPT
Vb (2)
Rajeev Sharan
 
PDF
Mean square error
Jay Patel
 
PPTX
Python project
Young Song
 
PPTX
Do...until loop structure
Jd Mercado
 
PPTX
Introduction to programming in MATLAB
mustafa_92
 
queue
umair khan
 
Python project2
Young Song
 
Mean square error
Jay Patel
 
Python project
Young Song
 
Do...until loop structure
Jd Mercado
 
Introduction to programming in MATLAB
mustafa_92
 

Similar to Loop Introduction for Loop while Loop do while Loop Nested Loops Values of functions and assignment expressions break and continue Statements (20)

PPTX
Loops c++
Shivani Singh
 
PPTX
Loops IN COMPUTER SCIENCE STANDARD 11 BY KR
Krishna Raj
 
PPT
Looping in c++
deekshagopaliya
 
PPT
Looping in c++
deekshagopaliya
 
PPTX
Cs1123 6 loops
TAlha MAlik
 
PPTX
Loop structures
tazeem sana
 
PPTX
Iteration statements.pptxjdjdjsksodhdjsnsk
aryanpandey9997
 
PDF
Loops in c++
Rebin Daho
 
PPT
Control structures repetition
Online
 
PDF
presentationonnestingofloops-110228071935-phpapp01.pdf
JounAbbas4
 
PPTX
Presentation on nesting of loops
bsdeol28
 
PPT
Deeksha gopaliya
deekshagopaliya
 
PPTX
Loops in c
RekhaBudhwar
 
PPTX
Lecture 5
Mohammed Khan
 
PDF
Loops
EMAD ALHOTHLY
 
PPT
Loops
abdulmanan366
 
PDF
LOOPING_STATEMENT c++ pptx from bgctub university
jebinchowdhury68
 
PPSX
C lecture 3 control statements slideshare
Gagan Deep
 
Loops c++
Shivani Singh
 
Loops IN COMPUTER SCIENCE STANDARD 11 BY KR
Krishna Raj
 
Looping in c++
deekshagopaliya
 
Looping in c++
deekshagopaliya
 
Cs1123 6 loops
TAlha MAlik
 
Loop structures
tazeem sana
 
Iteration statements.pptxjdjdjsksodhdjsnsk
aryanpandey9997
 
Loops in c++
Rebin Daho
 
Control structures repetition
Online
 
presentationonnestingofloops-110228071935-phpapp01.pdf
JounAbbas4
 
Presentation on nesting of loops
bsdeol28
 
Deeksha gopaliya
deekshagopaliya
 
Loops in c
RekhaBudhwar
 
Lecture 5
Mohammed Khan
 
LOOPING_STATEMENT c++ pptx from bgctub university
jebinchowdhury68
 
C lecture 3 control statements slideshare
Gagan Deep
 
Ad

More from imtiazalijoono (20)

PDF
Embedded systems io programming
imtiazalijoono
 
PDF
Embedded systems tools & peripherals
imtiazalijoono
 
PPTX
Importance of reading and its types.
imtiazalijoono
 
PPTX
Negative amplifiers and its types Positive feedback and Negative feedback
imtiazalijoono
 
PPTX
Multistage amplifiers and Name of coupling Name of multistage amplifier
imtiazalijoono
 
PDF
Programming Fundamentals and basic knowledge
imtiazalijoono
 
PDF
Programming Fundamentals Functions in C and types
imtiazalijoono
 
PDF
Software Development Software development process
imtiazalijoono
 
PDF
Programming Fundamentals Decisions
imtiazalijoono
 
PDF
C Building Blocks
imtiazalijoono
 
PDF
Programming Fundamentals Arrays and Strings
imtiazalijoono
 
PPTX
Programming Fundamentals and Programming Languages Concepts Translators
imtiazalijoono
 
PPTX
Programming Fundamentals and Programming Languages Concepts
imtiazalijoono
 
DOCX
Programming Global variable
imtiazalijoono
 
PPTX
Array Introduction One-dimensional array Multidimensional array
imtiazalijoono
 
PPTX
NTRODUCTION TO COMPUTER PROGRAMMING Loop as repetitive statement,
imtiazalijoono
 
PPTX
Arithmetic and Arithmetic assignment operators
imtiazalijoono
 
PPTX
INTRODUCTION TO COMPUTER PROGRAMMING
imtiazalijoono
 
PPTX
COMPUTER PROGRAMMING
imtiazalijoono
 
PPTX
COMPUTER PROGRAMMING
imtiazalijoono
 
Embedded systems io programming
imtiazalijoono
 
Embedded systems tools & peripherals
imtiazalijoono
 
Importance of reading and its types.
imtiazalijoono
 
Negative amplifiers and its types Positive feedback and Negative feedback
imtiazalijoono
 
Multistage amplifiers and Name of coupling Name of multistage amplifier
imtiazalijoono
 
Programming Fundamentals and basic knowledge
imtiazalijoono
 
Programming Fundamentals Functions in C and types
imtiazalijoono
 
Software Development Software development process
imtiazalijoono
 
Programming Fundamentals Decisions
imtiazalijoono
 
C Building Blocks
imtiazalijoono
 
Programming Fundamentals Arrays and Strings
imtiazalijoono
 
Programming Fundamentals and Programming Languages Concepts Translators
imtiazalijoono
 
Programming Fundamentals and Programming Languages Concepts
imtiazalijoono
 
Programming Global variable
imtiazalijoono
 
Array Introduction One-dimensional array Multidimensional array
imtiazalijoono
 
NTRODUCTION TO COMPUTER PROGRAMMING Loop as repetitive statement,
imtiazalijoono
 
Arithmetic and Arithmetic assignment operators
imtiazalijoono
 
INTRODUCTION TO COMPUTER PROGRAMMING
imtiazalijoono
 
COMPUTER PROGRAMMING
imtiazalijoono
 
COMPUTER PROGRAMMING
imtiazalijoono
 
Ad

Recently uploaded (20)

PPTX
Optimizing Cancer Screening With MCED Technologies: From Science to Practical...
i3 Health
 
PDF
07.15.2025 - Managing Your Members Using a Membership Portal.pdf
TechSoup
 
PPTX
How to Configure Prepayments in Odoo 18 Sales
Celine George
 
PPTX
SCHOOL-BASED SEXUAL HARASSMENT PREVENTION AND RESPONSE WORKSHOP
komlalokoe
 
PPTX
CBSE to Conduct Class 10 Board Exams Twice a Year Starting 2026 .pptx
Schoolsof Dehradun
 
PPTX
Views on Education of Indian Thinkers J.Krishnamurthy..pptx
ShrutiMahanta1
 
PPT
digestive system for Pharm d I year HAP
rekhapositivity
 
PPTX
Blanket Order in Odoo 17 Purchase App - Odoo Slides
Celine George
 
PPSX
Health Planning in india - Unit 03 - CHN 2 - GNM 3RD YEAR.ppsx
Priyanshu Anand
 
PPTX
nutriquiz grade 4.pptx...............................................
ferdinandsanbuenaven
 
PPTX
How to Configure Access Rights of Manufacturing Orders in Odoo 18 Manufacturing
Celine George
 
PPTX
Mrs Mhondiwa Introduction to Algebra class
sabinaschimanga
 
PPTX
Accounting Skills Paper-I, Preparation of Vouchers
Dr. Sushil Bansode
 
PPTX
How to Configure Storno Accounting in Odoo 18 Accounting
Celine George
 
PDF
BÀI TẬP BỔ TRỢ THEO LESSON TIẾNG ANH - I-LEARN SMART WORLD 7 - CẢ NĂM - CÓ ĐÁ...
Nguyen Thanh Tu Collection
 
PPTX
The Human Eye and The Colourful World Class 10 NCERT Science.pptx
renutripathibharat
 
PPTX
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
PPTX
How to Manage Promotions in Odoo 18 Sales
Celine George
 
PPTX
2025 Winter SWAYAM NPTEL & A Student.pptx
Utsav Yagnik
 
PDF
1, 2, 3… E MAIS UM CICLO CHEGA AO FIM!.pdf
Colégio Santa Teresinha
 
Optimizing Cancer Screening With MCED Technologies: From Science to Practical...
i3 Health
 
07.15.2025 - Managing Your Members Using a Membership Portal.pdf
TechSoup
 
How to Configure Prepayments in Odoo 18 Sales
Celine George
 
SCHOOL-BASED SEXUAL HARASSMENT PREVENTION AND RESPONSE WORKSHOP
komlalokoe
 
CBSE to Conduct Class 10 Board Exams Twice a Year Starting 2026 .pptx
Schoolsof Dehradun
 
Views on Education of Indian Thinkers J.Krishnamurthy..pptx
ShrutiMahanta1
 
digestive system for Pharm d I year HAP
rekhapositivity
 
Blanket Order in Odoo 17 Purchase App - Odoo Slides
Celine George
 
Health Planning in india - Unit 03 - CHN 2 - GNM 3RD YEAR.ppsx
Priyanshu Anand
 
nutriquiz grade 4.pptx...............................................
ferdinandsanbuenaven
 
How to Configure Access Rights of Manufacturing Orders in Odoo 18 Manufacturing
Celine George
 
Mrs Mhondiwa Introduction to Algebra class
sabinaschimanga
 
Accounting Skills Paper-I, Preparation of Vouchers
Dr. Sushil Bansode
 
How to Configure Storno Accounting in Odoo 18 Accounting
Celine George
 
BÀI TẬP BỔ TRỢ THEO LESSON TIẾNG ANH - I-LEARN SMART WORLD 7 - CẢ NĂM - CÓ ĐÁ...
Nguyen Thanh Tu Collection
 
The Human Eye and The Colourful World Class 10 NCERT Science.pptx
renutripathibharat
 
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
How to Manage Promotions in Odoo 18 Sales
Celine George
 
2025 Winter SWAYAM NPTEL & A Student.pptx
Utsav Yagnik
 
1, 2, 3… E MAIS UM CICLO CHEGA AO FIM!.pdf
Colégio Santa Teresinha
 

Loop Introduction for Loop while Loop do while Loop Nested Loops Values of functions and assignment expressions break and continue Statements

  • 3. 3 Outline • Introduction • for Loop • while Loop • do while Loop • Nested Loops • Values of functions and assignment expressions • break and continue Statements
  • 4. 4 Introduction • A loop causes a section of program to be repeated a certain number of times • The repetition continues till the condition remains true: When the condition becomes false the loops exits and the control passes to the statements following the loop. • C++ allows (03) three kinds of loops: – FOR – WHILE – DO … WHILE
  • 5. for Loop • The for loop executes a section of code a fixed number of times • It is usually (although not always) used when it is known in advance how many times the code should be executed.
  • 6. j is loop variable
  • 9. for Loop: Example for Loop: Exercises 1. Square all numbers from 1 to 10
  • 10. 2. Write a program that generates the following table: 2 x 1 = 2 2 x 2 = 4 2 x 3 = 6 2 x 4 = 8 2 x 5 = 10 3. Print even and odd number from 0 and 1 respectively up to 20 4. Write a program that displays the output: WHILE Loop n is loop variable
  • 11. • A while loop repeatedly executes a target statement as long as a given condition is true.
  • 13. WHILE Loop: Example #include <stdio.h> #include <conio.h> int main() { int n = 99; while (n!=0) scanf(“%d”, &n); getch(); } DO … WHILE Loop
  • 14. Unlike FOR and WHILE loops, which test the loop condition at the top of the loop, the DO … WHILE loop checks its condition at the bottom of the loop. The DO … WHILE loop is used when it is guaranteed that the loop body will be executed at least once, even if the test expression initially returns false.