Concept of Loop: Prepared by
Concept of Loop: Prepared by
Prepared By
Priyanka Das
ID: 20104014
Content
Topic Objective
Introduction
Types of looping
while
do-while
for
Conclusion
Topic Objective
Understand the basics of looping.
To use the while, do-while and for repetition statement to
execute statements in a program repeatedly.
INTRODUCTION
Statements in a program are executed one after the other
ex: statement 1;
statement 2;
:
statement n;
Statements
Conditio
n
Evaluate
d
true
false
true Conditio
n
Statements Evaluate
d
false
TYPES OF LOOP
while loop
do-while loop
for loop
while
Loop
It has a loop condition only that is tested before each
iteration to decide whether to continue or terminate the
loop.
The body of a while loop will execute zero or
more times
Syntax:
while (<condition>){
<statement/block>;
}
Flow
Example : diagram
int i=0;
while(i<3){ Conditio
n
Evaluate
printf(“Hello\n”); d
false
true
i++;
Statements
}
Output
: Hello
Hello
Hello
do…while Loop
Do while has a loop condition only that is tested after
each iteration to decide whether to continue with next
iteration or terminate the loop.
Syntax:
do{
<statement/block>;
}while(condition);
Example: Flow diagram
int i=0;
do{
Output:
Conditio
n
Evaluate
d
Hello false
Hello
Hello
for Loop
for loop has three parts:
Conditio
n
Evaluate
d
true false
Statements
increament
Example:
for(i=0; i<3; i++)
{
printf(“Hello\n”);
}
Output:
Hello
Hello
CONCLUSION
Importance of loops in any programming language is
immense, they allow us to reduce the number of lines in a
code, making our code more readable and efficient.
THANK YOU