For



for I in range(0,7) 

String

loop through each character

for x in "banana": 
print(x)

List

loop through each item in the list

fruits = ["apple", "banana", "cherry"] 
for x in fruits:
print(x)


Exit The Loop

you can use the break statement

fruits = ["apple", "banana", "cherry"] 
for x in fruits:
  if x == "banana":
    break
  print(x)



Nested Loops

The "inner loop" will be executed one time for each iteration of the "outer loop":

adj = ["red", "big", "tasty"] 
fruits = ["apple", "banana", "cherry"]

for x in adj:
for y in fruits:
print(x, y)


pass Statement

for loops cannot be empty, but if you for some reason have a for loop with no content, put in the pass statement to avoid getting an error.

for x in [10, 20, 30]: 
pass



© 2025 Better Solutions Limited. All Rights Reserved. © 2025 Better Solutions Limited TopPrev