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
PPT-Q1-WK-3-ENGLISH Revised Matatag Grade 3.pptx
reijhongidayawan02
 
PDF
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
PDF
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
PPTX
Post Dated Cheque(PDC) Management in Odoo 18
Celine George
 
PDF
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
PDF
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
PDF
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
PPTX
How to Configure Re-Ordering From Portal in Odoo 18 Website
Celine George
 
PPTX
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
PPTX
How to Set Up Tags in Odoo 18 - Odoo Slides
Celine George
 
PPTX
HUMAN RESOURCE MANAGEMENT: RECRUITMENT, SELECTION, PLACEMENT, DEPLOYMENT, TRA...
PRADEEP ABOTHU
 
PPTX
Identifying elements in the story. Arrange the events in the story
geraldineamahido2
 
PDF
Mahidol_Change_Agent_Note_2025-06-27-29_MUSEF
Tassanee Lerksuthirat
 
PDF
Characteristics, Strengths and Weaknesses of Quantitative Research.pdf
Thelma Villaflores
 
PDF
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
PPTX
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
PDF
The Different Types of Non-Experimental Research
Thelma Villaflores
 
PDF
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
PPTX
care of patient with elimination needs.pptx
Rekhanjali Gupta
 
PPTX
I AM MALALA The Girl Who Stood Up for Education and was Shot by the Taliban...
Beena E S
 
PPT-Q1-WK-3-ENGLISH Revised Matatag Grade 3.pptx
reijhongidayawan02
 
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
Post Dated Cheque(PDC) Management in Odoo 18
Celine George
 
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
How to Configure Re-Ordering From Portal in Odoo 18 Website
Celine George
 
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
How to Set Up Tags in Odoo 18 - Odoo Slides
Celine George
 
HUMAN RESOURCE MANAGEMENT: RECRUITMENT, SELECTION, PLACEMENT, DEPLOYMENT, TRA...
PRADEEP ABOTHU
 
Identifying elements in the story. Arrange the events in the story
geraldineamahido2
 
Mahidol_Change_Agent_Note_2025-06-27-29_MUSEF
Tassanee Lerksuthirat
 
Characteristics, Strengths and Weaknesses of Quantitative Research.pdf
Thelma Villaflores
 
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
The Different Types of Non-Experimental Research
Thelma Villaflores
 
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
care of patient with elimination needs.pptx
Rekhanjali Gupta
 
I AM MALALA The Girl Who Stood Up for Education and was Shot by the Taliban...
Beena E S
 

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.