2. ABOUT ME
Md. Emon Rana
Id : 20104009
Batch : Spring-20
Mobile : 019414562
Email : emonrana@gmail.com
3. 1. What is loop
2. How it works
3. Parts of loop
4. Type of loop
* For Loop
5. Example
CONTENTS
4. WHAT IS LOOP
• The loop statements allow a set of instructions to be performed
repeatedly until a certain condition is fulfilled.
5. HOW IT WORKS
Running
A sequence of statement is executed
until a specified condition is true.
This sequence of statement to be
executed is kept inside the curly
braces {} known as loop body. After
every execution of loop body,
condition is checked, and if it is
found to be true the loop body is
executed again. When condition
check comes out to be false, the
loop body will not be executed.
Execute loop
Loop
Entry
False
Test
conditi
on
Out of
loop
True
6. PARTS OF LOOP
• Initialization Expression(s) : initialize(s) the loop variables in the
beginning of the loop.
• Test Expression : decides whether the loop will be executed (if
test expression is true) or not (if test expression is false).
• Increment/Decrement : This part increments or decrements the value of a variable
that is being checked
• The Body-of-the-Loop : contains statements to be executed
repeatedly.
For(Initialization; test expression;
increment/decrement)
{
body;
7. TYPE OF LOOP
There are various ways to use loops. Mainly usage among of
them are :
While
loop
Repeats a statement or group of statements until a given condition is true.
It tests the condition before executing the loop body.
For loop Execute a sequence of statements multiple times and abbreviates the code
that manages the loop variable.
Do…
While
loop
Like a while statement, except that it tests the condition at the end of the
loop body
Nested
loop
You can use one or more loop inside any another while, for or do..while
loop.
8. FOR LOOP
For-loop is a type of loop. For-loop is a control flow statement for specifying
iteration, which allows code to be executed repeatedly.
9. STRUCTURE OF FOR LOOP
For(Initialization; test expression; increment/decrement)
{
body;
}
The
initialization is
executed once
before the
loop begins
The statement is
executed until
the condition
becomes false
The increment portion
is executed at the end
of each iteration