0% found this document useful (0 votes)
25 views16 pages

Concept of Loop: Prepared by

This document discusses looping concepts in programming. There are three main types of loops: while loops, do-while loops, and for loops. While loops check a condition before each iteration. Do-while loops check a condition after each iteration so the body is executed at least once. For loops allow initialization of a counter, a condition to check each iteration, and incrementation of the counter after each iteration. Loops are useful for executing blocks of code repeatedly to make programs more efficient.

Uploaded by

K-link Bangla
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views16 pages

Concept of Loop: Prepared by

This document discusses looping concepts in programming. There are three main types of loops: while loops, do-while loops, and for loops. While loops check a condition before each iteration. Do-while loops check a condition after each iteration so the body is executed at least once. For loops allow initialization of a counter, a condition to check each iteration, and incrementation of the counter after each iteration. Loops are useful for executing blocks of code repeatedly to make programs more efficient.

Uploaded by

K-link Bangla
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 16

CONCEPT OF LOOP

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;

Sometimes, the user want to execute a set of statements


repeatedly.
Loop statements are used to repeat the execution
of statement or blocks.

Iteration of a loop: the number of times the body of loop is


executed.

 Two types of loop structure are:


Pretest : Entry - controlled loop
Posttest : Exit – controlled loop
Pretest Vs. Posttest
Pretest : Condition is tested before each iteration to check
if loops should occur.

Posttest : Condition is tested after each iteration to check


if loop should continue (at least a single iteration occurs).

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{

Printf (“Hello\n”); Statements


i++;
} while (i<3); true

Output:
Conditio
n
Evaluate
d

Hello false

Hello

Hello
for Loop
for loop has three parts:

 Initializer is executed at start of loop.

 Loop condition is tested before iteration to


decide
whether to continue or terminate the loop.

 Increment is executed at the end of each loop iteration.


Syntax:
for( [initialize];
[condition];
[incrementor] )
{
<statement/block>;
}

Flow diagram initialization

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

You might also like