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.

More Related Content

PPTX
Loops in c
PDF
3. Flow Controls in C (Part II).pdf
DOCX
loops and iteration.docx
PDF
Loop and while Loop
PPTX
PPTX
While , For , Do-While Loop
PDF
PPTX
C Programming: Looping Statements in C Pgm
Loops in c
3. Flow Controls in C (Part II).pdf
loops and iteration.docx
Loop and while Loop
While , For , Do-While Loop
C Programming: Looping Statements in C Pgm

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

PPTX
Loops c++
DOCX
itretion.docx
PDF
Loops in C Programming | for Loop | do-while Loop | while Loop | Nested Loop
PPTX
Loops Basics
PPTX
Loop structures
PPTX
Loop in C Properties & Applications
PPTX
The Loops
PPTX
Loops In C++
PDF
[ITP - Lecture 11] Loops in C/C++
PPTX
Introduction to Java Programming - Lecture 11.pptx
PPTX
Loops IN COMPUTER SCIENCE STANDARD 11 BY KR
PPTX
Loop (Computer programming and utilization)
PPTX
Types of loops in c language
PPTX
Loops in c
PPT
Looping statements in Java
PDF
Java Repetiotion Statements
PPTX
Looping and Switchcase BDCR
PDF
ICP - Lecture 9
Loops c++
itretion.docx
Loops in C Programming | for Loop | do-while Loop | while Loop | Nested Loop
Loops Basics
Loop structures
Loop in C Properties & Applications
The Loops
Loops In C++
[ITP - Lecture 11] Loops in C/C++
Introduction to Java Programming - Lecture 11.pptx
Loops IN COMPUTER SCIENCE STANDARD 11 BY KR
Loop (Computer programming and utilization)
Types of loops in c language
Loops in c
Looping statements in Java
Java Repetiotion Statements
Looping and Switchcase BDCR
ICP - Lecture 9
Ad

Recently uploaded (20)

PPTX
Foundation to blockchain - A guide to Blockchain Tech
PPT
CRASH COURSE IN ALTERNATIVE PLUMBING CLASS
PDF
Digital Logic Computer Design lecture notes
PDF
composite construction of structures.pdf
PPTX
web development for engineering and engineering
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PPT
Project quality management in manufacturing
PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
PPTX
Lecture Notes Electrical Wiring System Components
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PPT
Mechanical Engineering MATERIALS Selection
PPTX
additive manufacturing of ss316l using mig welding
PPTX
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
PDF
Well-logging-methods_new................
PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
PPTX
Geodesy 1.pptx...............................................
PPTX
bas. eng. economics group 4 presentation 1.pptx
PPTX
OOP with Java - Java Introduction (Basics)
PDF
PPT on Performance Review to get promotions
PDF
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
Foundation to blockchain - A guide to Blockchain Tech
CRASH COURSE IN ALTERNATIVE PLUMBING CLASS
Digital Logic Computer Design lecture notes
composite construction of structures.pdf
web development for engineering and engineering
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
Project quality management in manufacturing
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
Lecture Notes Electrical Wiring System Components
CYBER-CRIMES AND SECURITY A guide to understanding
Mechanical Engineering MATERIALS Selection
additive manufacturing of ss316l using mig welding
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
Well-logging-methods_new................
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
Geodesy 1.pptx...............................................
bas. eng. economics group 4 presentation 1.pptx
OOP with Java - Java Introduction (Basics)
PPT on Performance Review to get promotions
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
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.