際際滷

際際滷Share a Scribd company logo
LOOP IN
PROGRAMMING
LECTURE 3
MUQADDAS BIN TAHIR
LECTURE
CONTENTS
Purpose of LOOP
1
Types of LOOP
2
Format of Loop
3
Examples of LOOP
4
Different facts about LOOP
5
A loop in programming is a control
structure that allows a block of code to be
executed repeatedly, based on a specified
condition. Loops are useful when we need
to perform a repetitive task, reducing the
amount of code we write and making
programs more efficient.
PURPOSE OF LOOP
BASIC STRUCTUE
OF LOOP
There are three common types of loops in
C++:
1.for loop
2.while loop
3.do-while loop
TYPES OF LOOP
A for loop is a repetition control structure that allows you to
efficiently write a loop that needs to execute a specific number of
times.
Syntax
The syntax of a for loop in C++ is 
for ( init; condition; increment ) {
statement(s);
FOR LOOP
 In a for loop, the initialization step runs first and only once, allowing you
to declare and initialize loop control variables. You can leave it empty,
but a semicolon is required.
 Next, the condition is checked. If true, the loop body executes; if false,
control moves to the statement after the loop.
 After the loop body runs, control moves to the increment step, which
can also be empty but requires a semicolon.
 The condition is then rechecked. If true, the loop repeats (body,
increment, condition). Once the condition is false, the loop ends.
FOR LOOP
BASIC STRUCTUE
OF LOOP
EXAMPLE 1
LOOP
Heres a simple algorithm to print the message "I Love
Pakistan" 7 times using a loop:
for (int i = 1; i <= 7; i++)
{
cout << "I Love Pakistan" << endl;
}
EXAMPLE 2 LOOP
Heres a C++ program to print counting from 1 to 500 using a
for loop:
 The for loop starts with i = 1 and continues as long as i <=
500.
 It increments i by 1 in each iteration and prints the value
of i.
for (int i = 1; i <= 500; i++)
{
cout << i << " ";
EXAMPLE 2 LOOP
 Heres a C++ program to display even numbers from 1 to
100 using a for loop and an if condition:
for (int i = 1; i <= 100; i++)
{
if (i % 2 == 0)
{
cout << i << " ";
}
}
SOME
INTERESTING
FACTS
FACT 1
Nested Loops:
Loops can be nested inside other
loops, allowing you to perform
complex iterations. For instance, in a
two-dimensional array, a nested loop
is used to iterate through rows and
columns. However, care must be
taken as nested loops can
significantly increase time complexity.
FACT 2
Infinite Loops:
A loop can run indefinitely if its exit
condition is never met, resulting in
an infinite loop. While infinite
loops can be useful in certain
scenarios like event listeners, they
often occur by mistake and can
crash programs or consume
excessive resources if not handled
FACT 3
Break and Continue Statements:
Loops can be controlled using the
break and continue statements.
The break statement immediately
exits the loop, while continue skips
the current iteration and proceeds
with the next one. These are handy
when certain conditions inside the
loop need to be handled

More Related Content

Similar to LOOPS IN PROGRAMMING - Muqaddas Bin Tahir .pptx (20)

Lec7 - Loops updated.pptx
Lec7 - Loops updated.pptxLec7 - Loops updated.pptx
Lec7 - Loops updated.pptx
NaumanRasheed11
Chp4_C++_Control Structures-Part2_Iteration.pptx
Chp4_C++_Control Structures-Part2_Iteration.pptxChp4_C++_Control Structures-Part2_Iteration.pptx
Chp4_C++_Control Structures-Part2_Iteration.pptx
ssuser10ed71
C language (Part 2)
C language (Part 2)C language (Part 2)
C language (Part 2)
Dr. SURBHI SAROHA
Iteration
IterationIteration
Iteration
Liam Dunphy
Iterative control structures, looping, types of loops, loop working
Iterative control structures, looping, types of loops, loop workingIterative control structures, looping, types of loops, loop working
Iterative control structures, looping, types of loops, loop working
Neeru Mittal
Looping statements
Looping statementsLooping statements
Looping statements
AbhishekMondal42
Looping in c language
Looping in c languageLooping in c language
Looping in c language
Infinity Tech Solutions
Loop structures
Loop structuresLoop structures
Loop structures
tazeem sana
prt123.pptx
prt123.pptxprt123.pptx
prt123.pptx
ASADKS
LOOP STATEMENTS AND TYPES OF LOOP IN C LANGUAGE BY RIZWAN
LOOP STATEMENTS AND TYPES OF LOOP IN C LANGUAGE BY RIZWANLOOP STATEMENTS AND TYPES OF LOOP IN C LANGUAGE BY RIZWAN
LOOP STATEMENTS AND TYPES OF LOOP IN C LANGUAGE BY RIZWAN
MD RIZWAN MOLLA
csharp repitition structures
csharp repitition structurescsharp repitition structures
csharp repitition structures
Micheal Ogundero
Loops in python.pptx/ introduction to loops in python
Loops in python.pptx/ introduction to loops in pythonLoops in python.pptx/ introduction to loops in python
Loops in python.pptx/ introduction to loops in python
kinzaayaz464
introduction to loops in python/python loops
introduction to loops in python/python loopsintroduction to loops in python/python loops
introduction to loops in python/python loops
kinzaayaz464
Loop in C Properties & Applications
Loop in C Properties & ApplicationsLoop in C Properties & Applications
Loop in C Properties & Applications
Emroz Sardar
whileloop-161225171903.pdf
whileloop-161225171903.pdfwhileloop-161225171903.pdf
whileloop-161225171903.pdf
BasirKhan21
Programming loop
Programming loopProgramming loop
Programming loop
University of Potsdam
computing for engineering , data porgraming
computing for engineering , data porgramingcomputing for engineering , data porgraming
computing for engineering , data porgraming
yazaj12
While loop
While loopWhile loop
While loop
Feras_83
itretion.docx
itretion.docxitretion.docx
itretion.docx
JavvajiVenkat
Cs1123 6 loops
Cs1123 6 loopsCs1123 6 loops
Cs1123 6 loops
TAlha MAlik
Lec7 - Loops updated.pptx
Lec7 - Loops updated.pptxLec7 - Loops updated.pptx
Lec7 - Loops updated.pptx
NaumanRasheed11
Chp4_C++_Control Structures-Part2_Iteration.pptx
Chp4_C++_Control Structures-Part2_Iteration.pptxChp4_C++_Control Structures-Part2_Iteration.pptx
Chp4_C++_Control Structures-Part2_Iteration.pptx
ssuser10ed71
Iterative control structures, looping, types of loops, loop working
Iterative control structures, looping, types of loops, loop workingIterative control structures, looping, types of loops, loop working
Iterative control structures, looping, types of loops, loop working
Neeru Mittal
Loop structures
Loop structuresLoop structures
Loop structures
tazeem sana
prt123.pptx
prt123.pptxprt123.pptx
prt123.pptx
ASADKS
LOOP STATEMENTS AND TYPES OF LOOP IN C LANGUAGE BY RIZWAN
LOOP STATEMENTS AND TYPES OF LOOP IN C LANGUAGE BY RIZWANLOOP STATEMENTS AND TYPES OF LOOP IN C LANGUAGE BY RIZWAN
LOOP STATEMENTS AND TYPES OF LOOP IN C LANGUAGE BY RIZWAN
MD RIZWAN MOLLA
csharp repitition structures
csharp repitition structurescsharp repitition structures
csharp repitition structures
Micheal Ogundero
Loops in python.pptx/ introduction to loops in python
Loops in python.pptx/ introduction to loops in pythonLoops in python.pptx/ introduction to loops in python
Loops in python.pptx/ introduction to loops in python
kinzaayaz464
introduction to loops in python/python loops
introduction to loops in python/python loopsintroduction to loops in python/python loops
introduction to loops in python/python loops
kinzaayaz464
Loop in C Properties & Applications
Loop in C Properties & ApplicationsLoop in C Properties & Applications
Loop in C Properties & Applications
Emroz Sardar
whileloop-161225171903.pdf
whileloop-161225171903.pdfwhileloop-161225171903.pdf
whileloop-161225171903.pdf
BasirKhan21
computing for engineering , data porgraming
computing for engineering , data porgramingcomputing for engineering , data porgraming
computing for engineering , data porgraming
yazaj12
While loop
While loopWhile loop
While loop
Feras_83
Cs1123 6 loops
Cs1123 6 loopsCs1123 6 loops
Cs1123 6 loops
TAlha MAlik

Recently uploaded (20)

How to Configure Restaurants in Odoo 17 Point of Sale
How to Configure Restaurants in Odoo 17 Point of SaleHow to Configure Restaurants in Odoo 17 Point of Sale
How to Configure Restaurants in Odoo 17 Point of Sale
Celine George
The Broccoli Dog's inner voice (look A)
The Broccoli Dog's inner voice  (look A)The Broccoli Dog's inner voice  (look A)
The Broccoli Dog's inner voice (look A)
merasan
DUBLIN PROGRAM DUBLIN PROGRAM DUBLIN PROGRAM
DUBLIN PROGRAM DUBLIN PROGRAM DUBLIN PROGRAMDUBLIN PROGRAM DUBLIN PROGRAM DUBLIN PROGRAM
DUBLIN PROGRAM DUBLIN PROGRAM DUBLIN PROGRAM
vlckovar
How to Manage Putaway Rule in Odoo 17 Inventory
How to Manage Putaway Rule in Odoo 17 InventoryHow to Manage Putaway Rule in Odoo 17 Inventory
How to Manage Putaway Rule in Odoo 17 Inventory
Celine George
EDL 290F Week 3 - Mountaintop Views (2025).pdf
EDL 290F Week 3  - Mountaintop Views (2025).pdfEDL 290F Week 3  - Mountaintop Views (2025).pdf
EDL 290F Week 3 - Mountaintop Views (2025).pdf
Liz Walsh-Trevino
Useful environment methods in Odoo 18 - Odoo 際際滷s
Useful environment methods in Odoo 18 - Odoo 際際滷sUseful environment methods in Odoo 18 - Odoo 際際滷s
Useful environment methods in Odoo 18 - Odoo 際際滷s
Celine George
CBSE Arabic Grammar - Class 10 ppt.pptx
CBSE Arabic Grammar - Class 10   ppt.pptxCBSE Arabic Grammar - Class 10   ppt.pptx
CBSE Arabic Grammar - Class 10 ppt.pptx
suhail849886
The Constitution, Government and Law making bodies .
The Constitution, Government and Law making bodies .The Constitution, Government and Law making bodies .
The Constitution, Government and Law making bodies .
saanidhyapatel09
Rass MELAI : an Internet MELA Quiz Prelims - El Dorado 2025
Rass MELAI : an Internet MELA Quiz Prelims - El Dorado 2025Rass MELAI : an Internet MELA Quiz Prelims - El Dorado 2025
Rass MELAI : an Internet MELA Quiz Prelims - El Dorado 2025
Conquiztadors- the Quiz Society of Sri Venkateswara College
Research & Research Methods: Basic Concepts and Types.pptx
Research & Research Methods: Basic Concepts and Types.pptxResearch & Research Methods: Basic Concepts and Types.pptx
Research & Research Methods: Basic Concepts and Types.pptx
Dr. Sarita Anand
How to use Init Hooks in Odoo 18 - Odoo 際際滷s
How to use Init Hooks in Odoo 18 - Odoo 際際滷sHow to use Init Hooks in Odoo 18 - Odoo 際際滷s
How to use Init Hooks in Odoo 18 - Odoo 際際滷s
Celine George
cervical spine mobilization manual therapy .pdf
cervical spine mobilization manual therapy .pdfcervical spine mobilization manual therapy .pdf
cervical spine mobilization manual therapy .pdf
SamarHosni3
How to Setup WhatsApp in Odoo 17 - Odoo 際際滷s
How to Setup WhatsApp in Odoo 17 - Odoo 際際滷sHow to Setup WhatsApp in Odoo 17 - Odoo 際際滷s
How to Setup WhatsApp in Odoo 17 - Odoo 際際滷s
Celine George
Essentials of a Good PMO, presented by Aalok Sonawala
Essentials of a Good PMO, presented by Aalok SonawalaEssentials of a Good PMO, presented by Aalok Sonawala
Essentials of a Good PMO, presented by Aalok Sonawala
Association for Project Management
Kaun TALHA quiz Prelims - El Dorado 2025
Kaun TALHA quiz Prelims - El Dorado 2025Kaun TALHA quiz Prelims - El Dorado 2025
Kaun TALHA quiz Prelims - El Dorado 2025
Conquiztadors- the Quiz Society of Sri Venkateswara College
Computer Network Unit IV - Lecture Notes - Network Layer
Computer Network Unit IV - Lecture Notes - Network LayerComputer Network Unit IV - Lecture Notes - Network Layer
Computer Network Unit IV - Lecture Notes - Network Layer
Murugan146644
How to Configure Flexible Working Schedule in Odoo 18 Employee
How to Configure Flexible Working Schedule in Odoo 18 EmployeeHow to Configure Flexible Working Schedule in Odoo 18 Employee
How to Configure Flexible Working Schedule in Odoo 18 Employee
Celine George
Blind Spots in AI and Formulation Science Knowledge Pyramid (Updated Perspect...
Blind Spots in AI and Formulation Science Knowledge Pyramid (Updated Perspect...Blind Spots in AI and Formulation Science Knowledge Pyramid (Updated Perspect...
Blind Spots in AI and Formulation Science Knowledge Pyramid (Updated Perspect...
Ajaz Hussain
N.C. DPI's 2023 Language Diversity Briefing
N.C. DPI's 2023 Language Diversity BriefingN.C. DPI's 2023 Language Diversity Briefing
N.C. DPI's 2023 Language Diversity Briefing
Mebane Rash
FESTIVAL: SINULOG & THINGYAN-LESSON 4.pptx
FESTIVAL: SINULOG & THINGYAN-LESSON 4.pptxFESTIVAL: SINULOG & THINGYAN-LESSON 4.pptx
FESTIVAL: SINULOG & THINGYAN-LESSON 4.pptx
DanmarieMuli1
How to Configure Restaurants in Odoo 17 Point of Sale
How to Configure Restaurants in Odoo 17 Point of SaleHow to Configure Restaurants in Odoo 17 Point of Sale
How to Configure Restaurants in Odoo 17 Point of Sale
Celine George
The Broccoli Dog's inner voice (look A)
The Broccoli Dog's inner voice  (look A)The Broccoli Dog's inner voice  (look A)
The Broccoli Dog's inner voice (look A)
merasan
DUBLIN PROGRAM DUBLIN PROGRAM DUBLIN PROGRAM
DUBLIN PROGRAM DUBLIN PROGRAM DUBLIN PROGRAMDUBLIN PROGRAM DUBLIN PROGRAM DUBLIN PROGRAM
DUBLIN PROGRAM DUBLIN PROGRAM DUBLIN PROGRAM
vlckovar
How to Manage Putaway Rule in Odoo 17 Inventory
How to Manage Putaway Rule in Odoo 17 InventoryHow to Manage Putaway Rule in Odoo 17 Inventory
How to Manage Putaway Rule in Odoo 17 Inventory
Celine George
EDL 290F Week 3 - Mountaintop Views (2025).pdf
EDL 290F Week 3  - Mountaintop Views (2025).pdfEDL 290F Week 3  - Mountaintop Views (2025).pdf
EDL 290F Week 3 - Mountaintop Views (2025).pdf
Liz Walsh-Trevino
Useful environment methods in Odoo 18 - Odoo 際際滷s
Useful environment methods in Odoo 18 - Odoo 際際滷sUseful environment methods in Odoo 18 - Odoo 際際滷s
Useful environment methods in Odoo 18 - Odoo 際際滷s
Celine George
CBSE Arabic Grammar - Class 10 ppt.pptx
CBSE Arabic Grammar - Class 10   ppt.pptxCBSE Arabic Grammar - Class 10   ppt.pptx
CBSE Arabic Grammar - Class 10 ppt.pptx
suhail849886
The Constitution, Government and Law making bodies .
The Constitution, Government and Law making bodies .The Constitution, Government and Law making bodies .
The Constitution, Government and Law making bodies .
saanidhyapatel09
Research & Research Methods: Basic Concepts and Types.pptx
Research & Research Methods: Basic Concepts and Types.pptxResearch & Research Methods: Basic Concepts and Types.pptx
Research & Research Methods: Basic Concepts and Types.pptx
Dr. Sarita Anand
How to use Init Hooks in Odoo 18 - Odoo 際際滷s
How to use Init Hooks in Odoo 18 - Odoo 際際滷sHow to use Init Hooks in Odoo 18 - Odoo 際際滷s
How to use Init Hooks in Odoo 18 - Odoo 際際滷s
Celine George
cervical spine mobilization manual therapy .pdf
cervical spine mobilization manual therapy .pdfcervical spine mobilization manual therapy .pdf
cervical spine mobilization manual therapy .pdf
SamarHosni3
How to Setup WhatsApp in Odoo 17 - Odoo 際際滷s
How to Setup WhatsApp in Odoo 17 - Odoo 際際滷sHow to Setup WhatsApp in Odoo 17 - Odoo 際際滷s
How to Setup WhatsApp in Odoo 17 - Odoo 際際滷s
Celine George
Computer Network Unit IV - Lecture Notes - Network Layer
Computer Network Unit IV - Lecture Notes - Network LayerComputer Network Unit IV - Lecture Notes - Network Layer
Computer Network Unit IV - Lecture Notes - Network Layer
Murugan146644
How to Configure Flexible Working Schedule in Odoo 18 Employee
How to Configure Flexible Working Schedule in Odoo 18 EmployeeHow to Configure Flexible Working Schedule in Odoo 18 Employee
How to Configure Flexible Working Schedule in Odoo 18 Employee
Celine George
Blind Spots in AI and Formulation Science Knowledge Pyramid (Updated Perspect...
Blind Spots in AI and Formulation Science Knowledge Pyramid (Updated Perspect...Blind Spots in AI and Formulation Science Knowledge Pyramid (Updated Perspect...
Blind Spots in AI and Formulation Science Knowledge Pyramid (Updated Perspect...
Ajaz Hussain
N.C. DPI's 2023 Language Diversity Briefing
N.C. DPI's 2023 Language Diversity BriefingN.C. DPI's 2023 Language Diversity Briefing
N.C. DPI's 2023 Language Diversity Briefing
Mebane Rash
FESTIVAL: SINULOG & THINGYAN-LESSON 4.pptx
FESTIVAL: SINULOG & THINGYAN-LESSON 4.pptxFESTIVAL: SINULOG & THINGYAN-LESSON 4.pptx
FESTIVAL: SINULOG & THINGYAN-LESSON 4.pptx
DanmarieMuli1

LOOPS IN PROGRAMMING - Muqaddas Bin Tahir .pptx

  • 2. LECTURE CONTENTS Purpose of LOOP 1 Types of LOOP 2 Format of Loop 3 Examples of LOOP 4 Different facts about LOOP 5
  • 3. A loop in programming is a control structure that allows a block of code to be executed repeatedly, based on a specified condition. Loops are useful when we need to perform a repetitive task, reducing the amount of code we write and making programs more efficient. PURPOSE OF LOOP
  • 5. There are three common types of loops in C++: 1.for loop 2.while loop 3.do-while loop TYPES OF LOOP
  • 6. A for loop is a repetition control structure that allows you to efficiently write a loop that needs to execute a specific number of times. Syntax The syntax of a for loop in C++ is for ( init; condition; increment ) { statement(s); FOR LOOP
  • 7. In a for loop, the initialization step runs first and only once, allowing you to declare and initialize loop control variables. You can leave it empty, but a semicolon is required. Next, the condition is checked. If true, the loop body executes; if false, control moves to the statement after the loop. After the loop body runs, control moves to the increment step, which can also be empty but requires a semicolon. The condition is then rechecked. If true, the loop repeats (body, increment, condition). Once the condition is false, the loop ends. FOR LOOP
  • 9. EXAMPLE 1 LOOP Heres a simple algorithm to print the message "I Love Pakistan" 7 times using a loop: for (int i = 1; i <= 7; i++) { cout << "I Love Pakistan" << endl; }
  • 10. EXAMPLE 2 LOOP Heres a C++ program to print counting from 1 to 500 using a for loop: The for loop starts with i = 1 and continues as long as i <= 500. It increments i by 1 in each iteration and prints the value of i. for (int i = 1; i <= 500; i++) { cout << i << " ";
  • 11. EXAMPLE 2 LOOP Heres a C++ program to display even numbers from 1 to 100 using a for loop and an if condition: for (int i = 1; i <= 100; i++) { if (i % 2 == 0) { cout << i << " "; } }
  • 13. FACT 1 Nested Loops: Loops can be nested inside other loops, allowing you to perform complex iterations. For instance, in a two-dimensional array, a nested loop is used to iterate through rows and columns. However, care must be taken as nested loops can significantly increase time complexity.
  • 14. FACT 2 Infinite Loops: A loop can run indefinitely if its exit condition is never met, resulting in an infinite loop. While infinite loops can be useful in certain scenarios like event listeners, they often occur by mistake and can crash programs or consume excessive resources if not handled
  • 15. FACT 3 Break and Continue Statements: Loops can be controlled using the break and continue statements. The break statement immediately exits the loop, while continue skips the current iteration and proceeds with the next one. These are handy when certain conditions inside the loop need to be handled