Python-Looping.pptx
Python-Looping.pptx
LOOPS
Mariefel T. Basibas
Page 02
Chapter
4.1
Python
Loops For
Loops While
loops
The Break Statement
Continue Statement
Iterating with For Loop
Iterating with while Loop
Looping through an
Iterator
Python
Loop
In Python, looping
refers to the process of
executing a set of
statements repeatedly,
either for a specified
number of times or until
a particular condition is
met.
Python
Loop
There are two primary types of loops used in
Python:
Note: remember to
increment i, or else the
loop will continue
forever.
sample Codes
Example
using while
loop
While Loops: These
Outpu execute a set of
t
statements as long as a
condition is true.
The break Sample code
Statement
With the break statement we
can stop the loop even if the
while condition is true:
Outpu
t
Continue
The continue statement in
Statement
Python is used to skip the rest
of the code inside a loop for
the current iteration only.
Loop does not terminate but
Outpu
continues on with the next
t
iteration. This statement can
be used in both for and while
loops.
Iterating with
a For Loop
Code Output
Example
Iterate the values of a tuple: