LOOPS IN PYTHON
Loops are control structures in Python that allow you to execute a block of code repeatedly.
There are two main types of loops in Python:
for loop and while loop.
1. for Loop in python
The for loop iterates over a sequence (such as a list, tuple, or string) and executes the block
of code for each item in the sequence until the sequence is exhausted.
Syntax:
for i in range(1,6):
Print(i)
Output
2. While Loop in Python:
The while loop repeats a block of code as long as a specified condition is true. It continues
iterating until the condition evaluates to false.
Syntax:
i=1
while i<=4:
Print(i)
i+=1
OUTPUT
Loop Control Statements in Python
Python provides loop control statements to alter the flow of loops. These include break,
continue, and else statements.