PYTHON LOOPS
What is Loop?
Types of Loops?
What is for loop?
For example:
X = [1,2,3,4,5,8,10]
for i in x:
if i > 5:
print(“yes”)
print(i)
What is while loop?
While Loop: Repeats a block of code as long as a specified condition is true. It's useful when the number of iterations is not known.
For example:
i = 10
while i < 20
print(“yes”)
i = i+1
What is nested loop?
For example:
x = [1,2,3,4,5,6,7]
for i in x:
for j in x:
print(“yes”)
What is loop control statement?
.
What is break ?
For Example:
for i in range(10):
if i == 5:
break # Exit the loop when i is 5
print(i)
What is continue?
For Example:
for i in range(10):
if i % 2 == 0:
continue # Skip the even numbers
print(i)
What is pass?
For Example:
for i in range(5):
if i == 3:
pass # Do nothing when i is 3
print(i)