SlideShare a Scribd company logo
Topic Covered: Introduction to Loops
, while loop+ programs, For loop + do
while loop +programs, Programming
practice using loops.
LECTURE: 8
Life is all about Repetition.
We do same thing everyday
Introduction of loop
Loop is used to execute the block of code several times according to the condition
given in the loop. It means it executes the same code multiple times.
In programming, loops are used to repeat a block of code until a specified condition
is met.
Output:
Hello
Hello
Hello
Hello
Hello
loop(condition)
{
//statements
}
Types of
loop
C programming has three types of loops.
for loop
while loop
do...while loop
While Loop
•while is an entry control loop.
•Statements inside the body of while are
repeatedly executed till the condition is true.
•while is keyword.
•The syntax of the while loop is:
while (testExpression) {
// the body of the loop
}
How while loop
works?
How while loop works?
The while loop evaluates the test Expression inside
the parentheses ().
If test_Expression is true, statements inside the
body of while loop are executed.
Then, test_Expression is evaluated again.
The process goes on until test Expression is
evaluated to false.
If test_Expression is false, the loop terminates
(ends).
Write A Program to print 1 to n
using While loop?
Write A Program to print Odd numbers
between 1 to n using while loop.
WAP to print multiplication table
using while loop.
WAP to Sum of 5 numbers entered
by user using while loop.
WAP to find factors of a
number using while loop.
WAP to print reverse a number
while loop.
for loop
for is an entry control loop.
Statements inside the body of for are
repeatedly executed till the condition is true
for is keyword.
The syntax of the for loop is:
for (initialization; condition; updateStatement)
{
// statements
}
How for loop works?
How for loop works?
The initialization statement is executed only once.
Then, the test expression is evaluated. If the test
expression is evaluated to false, the for loop is
terminated.
However, if the test expression is evaluated to true,
statements inside the body of the for loop are executed,
and the update expression is updated.
Again the test expression is evaluated.
This process goes on until the test expression is false.
When the test expression is false, the loop terminates.
WAP to print numbers 1 to n using
for loop.
do while loop
•do while is an exit control loop.
•Statements inside the body of do while are repeatedly executed till
the condition is true.
•Do and while are keywords.
The do.. while loop is similar to the while loop with one
important difference. The body of do...while loop is executed
at least once. Only then, the test expression is evaluated.
The syntax of the do...while loop is:
do {
// the body of the loop
}
while (test_Expression);
How do...while loop
works?
•The body of do...while loop is executed once.
Only then, the test_Expression is evaluated.
•If test_Expression is true, the body of the
loop is executed
again and test_Expression is evaluated once
more.
•This process goes on
until test_Expression becomes false.
•If test_Expression is false, the loop ends.
WAP to print Odd numbers between
1 to n using do while loop.
WAP to find factors of a number
using do while loop.
Ad

Recommended

3. Flow Controls in C (Part II).pdf
3. Flow Controls in C (Part II).pdf
santosh147365
 
Java Repetiotion Statements
Java Repetiotion Statements
Huda Alameen
 
loops and iteration.docx
loops and iteration.docx
JavvajiVenkat
 
dizital pods session 5-loops.pptx
dizital pods session 5-loops.pptx
VijayKumarLokanadam
 
Loop structures
Loop structures
tazeem sana
 
Loop
Loop
MdEmonRana
 
Loop and while Loop
Loop and while Loop
JayBhavsar68
 
Loops In C++
Loops In C++
Banasthali Vidyapith
 
C language 2
C language 2
Arafat Bin Reza
 
While , For , Do-While Loop
While , For , Do-While Loop
Abhishek Choksi
 
cpu.pdf
cpu.pdf
RAJCHATTERJEE24
 
types of loops and what is loop
types of loops and what is loop
waheed dogar
 
What is to loop in c++
What is to loop in c++
03446940736
 
Loops in c++
Loops in c++
Rebin Daho
 
presentation on powerpoint template.pptx
presentation on powerpoint template.pptx
farantouqeer8
 
Loops c++
Loops c++
Shivani Singh
 
C Programming: Looping Statements in C Pgm
C Programming: Looping Statements in C Pgm
Navya Francis
 
Loop in C Properties & Applications
Loop in C Properties & Applications
Emroz Sardar
 
Loops
Loops
SAMYAKKHADSE
 
Cse lecture-7-c loop
Cse lecture-7-c loop
FarshidKhan
 
controlStatement.pptx, CONTROL STATEMENTS IN JAVA
controlStatement.pptx, CONTROL STATEMENTS IN JAVA
DrNeetuSharma5
 
Decision making and loop in C#
Decision making and loop in C#
Prasanna Kumar SM
 
Flow control in c++
Flow control in c++
Subhasis Nayak
 
nuts and bolts of c++
nuts and bolts of c++
guestfb6ada
 
Control_Statements.pptx
Control_Statements.pptx
Koteswari Kasireddy
 
Introduction To Programming with Python Lecture 2
Introduction To Programming with Python Lecture 2
Syed Farjad Zia Zaidi
 
Computer programming 2 Lesson 8
Computer programming 2 Lesson 8
MLG College of Learning, Inc
 
Loops in c programming
Loops in c programming
CHANDAN KUMAR
 
دراسة حاله لقرية تقع في جنوب غرب السودان
دراسة حاله لقرية تقع في جنوب غرب السودان
محمد قصص فتوتة
 
AI_Presentation (1). Artificial intelligence
AI_Presentation (1). Artificial intelligence
RoselynKaur8thD34
 

More Related Content

Similar to Lecture on Loop while loop for loop + program (20)

C language 2
C language 2
Arafat Bin Reza
 
While , For , Do-While Loop
While , For , Do-While Loop
Abhishek Choksi
 
cpu.pdf
cpu.pdf
RAJCHATTERJEE24
 
types of loops and what is loop
types of loops and what is loop
waheed dogar
 
What is to loop in c++
What is to loop in c++
03446940736
 
Loops in c++
Loops in c++
Rebin Daho
 
presentation on powerpoint template.pptx
presentation on powerpoint template.pptx
farantouqeer8
 
Loops c++
Loops c++
Shivani Singh
 
C Programming: Looping Statements in C Pgm
C Programming: Looping Statements in C Pgm
Navya Francis
 
Loop in C Properties & Applications
Loop in C Properties & Applications
Emroz Sardar
 
Loops
Loops
SAMYAKKHADSE
 
Cse lecture-7-c loop
Cse lecture-7-c loop
FarshidKhan
 
controlStatement.pptx, CONTROL STATEMENTS IN JAVA
controlStatement.pptx, CONTROL STATEMENTS IN JAVA
DrNeetuSharma5
 
Decision making and loop in C#
Decision making and loop in C#
Prasanna Kumar SM
 
Flow control in c++
Flow control in c++
Subhasis Nayak
 
nuts and bolts of c++
nuts and bolts of c++
guestfb6ada
 
Control_Statements.pptx
Control_Statements.pptx
Koteswari Kasireddy
 
Introduction To Programming with Python Lecture 2
Introduction To Programming with Python Lecture 2
Syed Farjad Zia Zaidi
 
Computer programming 2 Lesson 8
Computer programming 2 Lesson 8
MLG College of Learning, Inc
 
Loops in c programming
Loops in c programming
CHANDAN KUMAR
 
While , For , Do-While Loop
While , For , Do-While Loop
Abhishek Choksi
 
types of loops and what is loop
types of loops and what is loop
waheed dogar
 
What is to loop in c++
What is to loop in c++
03446940736
 
presentation on powerpoint template.pptx
presentation on powerpoint template.pptx
farantouqeer8
 
C Programming: Looping Statements in C Pgm
C Programming: Looping Statements in C Pgm
Navya Francis
 
Loop in C Properties & Applications
Loop in C Properties & Applications
Emroz Sardar
 
Cse lecture-7-c loop
Cse lecture-7-c loop
FarshidKhan
 
controlStatement.pptx, CONTROL STATEMENTS IN JAVA
controlStatement.pptx, CONTROL STATEMENTS IN JAVA
DrNeetuSharma5
 
Decision making and loop in C#
Decision making and loop in C#
Prasanna Kumar SM
 
nuts and bolts of c++
nuts and bolts of c++
guestfb6ada
 
Introduction To Programming with Python Lecture 2
Introduction To Programming with Python Lecture 2
Syed Farjad Zia Zaidi
 
Loops in c programming
Loops in c programming
CHANDAN KUMAR
 

Recently uploaded (20)

دراسة حاله لقرية تقع في جنوب غرب السودان
دراسة حاله لقرية تقع في جنوب غرب السودان
محمد قصص فتوتة
 
AI_Presentation (1). Artificial intelligence
AI_Presentation (1). Artificial intelligence
RoselynKaur8thD34
 
Kel.3_A_Review_on_Internet_of_Things_for_Defense_v3.pptx
Kel.3_A_Review_on_Internet_of_Things_for_Defense_v3.pptx
Endang Saefullah
 
NEW Strengthened Senior High School Gen Math.pptx
NEW Strengthened Senior High School Gen Math.pptx
DaryllWhere
 
Data Structures Module 3 Binary Trees Binary Search Trees Tree Traversals AVL...
Data Structures Module 3 Binary Trees Binary Search Trees Tree Traversals AVL...
resming1
 
Introduction to Python Programming Language
Introduction to Python Programming Language
merlinjohnsy
 
Rapid Prototyping for XR: Lecture 2 - Low Fidelity Prototyping.
Rapid Prototyping for XR: Lecture 2 - Low Fidelity Prototyping.
Mark Billinghurst
 
Industry 4.o the fourth revolutionWeek-2.pptx
Industry 4.o the fourth revolutionWeek-2.pptx
KNaveenKumarECE
 
Rapid Prototyping for XR: Lecture 6 - AI for Prototyping and Research Directi...
Rapid Prototyping for XR: Lecture 6 - AI for Prototyping and Research Directi...
Mark Billinghurst
 
System design handwritten notes guidance
System design handwritten notes guidance
Shabista Imam
 
Comparison of Flexible and Rigid Pavements in Bangladesh
Comparison of Flexible and Rigid Pavements in Bangladesh
Arifur Rahman
 
Deep Learning for Natural Language Processing_FDP on 16 June 2025 MITS.pptx
Deep Learning for Natural Language Processing_FDP on 16 June 2025 MITS.pptx
resming1
 
Tally.ERP 9 at a Glance.book - Tally Solutions .pdf
Tally.ERP 9 at a Glance.book - Tally Solutions .pdf
Shabista Imam
 
Structured Programming with C++ :: Kjell Backman
Structured Programming with C++ :: Kjell Backman
Shabista Imam
 
Industrial internet of things IOT Week-3.pptx
Industrial internet of things IOT Week-3.pptx
KNaveenKumarECE
 
Deep Learning for Image Processing on 16 June 2025 MITS.pptx
Deep Learning for Image Processing on 16 June 2025 MITS.pptx
resming1
 
Generative AI & Scientific Research : Catalyst for Innovation, Ethics & Impact
Generative AI & Scientific Research : Catalyst for Innovation, Ethics & Impact
AlqualsaDIResearchGr
 
International Journal of Advanced Information Technology (IJAIT)
International Journal of Advanced Information Technology (IJAIT)
ijait
 
Rapid Prototyping for XR: Lecture 5 - Cross Platform Development
Rapid Prototyping for XR: Lecture 5 - Cross Platform Development
Mark Billinghurst
 
Modern multi-proposer consensus implementations
Modern multi-proposer consensus implementations
François Garillot
 
دراسة حاله لقرية تقع في جنوب غرب السودان
دراسة حاله لقرية تقع في جنوب غرب السودان
محمد قصص فتوتة
 
AI_Presentation (1). Artificial intelligence
AI_Presentation (1). Artificial intelligence
RoselynKaur8thD34
 
Kel.3_A_Review_on_Internet_of_Things_for_Defense_v3.pptx
Kel.3_A_Review_on_Internet_of_Things_for_Defense_v3.pptx
Endang Saefullah
 
NEW Strengthened Senior High School Gen Math.pptx
NEW Strengthened Senior High School Gen Math.pptx
DaryllWhere
 
Data Structures Module 3 Binary Trees Binary Search Trees Tree Traversals AVL...
Data Structures Module 3 Binary Trees Binary Search Trees Tree Traversals AVL...
resming1
 
Introduction to Python Programming Language
Introduction to Python Programming Language
merlinjohnsy
 
Rapid Prototyping for XR: Lecture 2 - Low Fidelity Prototyping.
Rapid Prototyping for XR: Lecture 2 - Low Fidelity Prototyping.
Mark Billinghurst
 
Industry 4.o the fourth revolutionWeek-2.pptx
Industry 4.o the fourth revolutionWeek-2.pptx
KNaveenKumarECE
 
Rapid Prototyping for XR: Lecture 6 - AI for Prototyping and Research Directi...
Rapid Prototyping for XR: Lecture 6 - AI for Prototyping and Research Directi...
Mark Billinghurst
 
System design handwritten notes guidance
System design handwritten notes guidance
Shabista Imam
 
Comparison of Flexible and Rigid Pavements in Bangladesh
Comparison of Flexible and Rigid Pavements in Bangladesh
Arifur Rahman
 
Deep Learning for Natural Language Processing_FDP on 16 June 2025 MITS.pptx
Deep Learning for Natural Language Processing_FDP on 16 June 2025 MITS.pptx
resming1
 
Tally.ERP 9 at a Glance.book - Tally Solutions .pdf
Tally.ERP 9 at a Glance.book - Tally Solutions .pdf
Shabista Imam
 
Structured Programming with C++ :: Kjell Backman
Structured Programming with C++ :: Kjell Backman
Shabista Imam
 
Industrial internet of things IOT Week-3.pptx
Industrial internet of things IOT Week-3.pptx
KNaveenKumarECE
 
Deep Learning for Image Processing on 16 June 2025 MITS.pptx
Deep Learning for Image Processing on 16 June 2025 MITS.pptx
resming1
 
Generative AI & Scientific Research : Catalyst for Innovation, Ethics & Impact
Generative AI & Scientific Research : Catalyst for Innovation, Ethics & Impact
AlqualsaDIResearchGr
 
International Journal of Advanced Information Technology (IJAIT)
International Journal of Advanced Information Technology (IJAIT)
ijait
 
Rapid Prototyping for XR: Lecture 5 - Cross Platform Development
Rapid Prototyping for XR: Lecture 5 - Cross Platform Development
Mark Billinghurst
 
Modern multi-proposer consensus implementations
Modern multi-proposer consensus implementations
François Garillot
 
Ad

Lecture on Loop while loop for loop + program

  • 1. Topic Covered: Introduction to Loops , while loop+ programs, For loop + do while loop +programs, Programming practice using loops. LECTURE: 8
  • 2. Life is all about Repetition. We do same thing everyday
  • 3. Introduction of loop Loop is used to execute the block of code several times according to the condition given in the loop. It means it executes the same code multiple times. In programming, loops are used to repeat a block of code until a specified condition is met. Output: Hello Hello Hello Hello Hello loop(condition) { //statements }
  • 4. Types of loop C programming has three types of loops. for loop while loop do...while loop
  • 5. While Loop •while is an entry control loop. •Statements inside the body of while are repeatedly executed till the condition is true. •while is keyword. •The syntax of the while loop is: while (testExpression) { // the body of the loop }
  • 7. How while loop works? The while loop evaluates the test Expression inside the parentheses (). If test_Expression is true, statements inside the body of while loop are executed. Then, test_Expression is evaluated again. The process goes on until test Expression is evaluated to false. If test_Expression is false, the loop terminates (ends).
  • 8. Write A Program to print 1 to n using While loop?
  • 9. Write A Program to print Odd numbers between 1 to n using while loop.
  • 10. WAP to print multiplication table using while loop.
  • 11. WAP to Sum of 5 numbers entered by user using while loop.
  • 12. WAP to find factors of a number using while loop.
  • 13. WAP to print reverse a number while loop.
  • 14. for loop for is an entry control loop. Statements inside the body of for are repeatedly executed till the condition is true for is keyword. The syntax of the for loop is: for (initialization; condition; updateStatement) { // statements }
  • 15. How for loop works?
  • 16. How for loop works? The initialization statement is executed only once. Then, the test expression is evaluated. If the test expression is evaluated to false, the for loop is terminated. However, if the test expression is evaluated to true, statements inside the body of the for loop are executed, and the update expression is updated. Again the test expression is evaluated. This process goes on until the test expression is false. When the test expression is false, the loop terminates.
  • 17. WAP to print numbers 1 to n using for loop.
  • 18. do while loop •do while is an exit control loop. •Statements inside the body of do while are repeatedly executed till the condition is true. •Do and while are keywords. The do.. while loop is similar to the while loop with one important difference. The body of do...while loop is executed at least once. Only then, the test expression is evaluated. The syntax of the do...while loop is: do { // the body of the loop } while (test_Expression);
  • 19. How do...while loop works? •The body of do...while loop is executed once. Only then, the test_Expression is evaluated. •If test_Expression is true, the body of the loop is executed again and test_Expression is evaluated once more. •This process goes on until test_Expression becomes false. •If test_Expression is false, the loop ends.
  • 20. WAP to print Odd numbers between 1 to n using do while loop.
  • 21. WAP to find factors of a number using do while loop.