2.4.2.2 for Loop
Python Programming
A for loop repeats a block of code a specific number of times. It is commonly used to iterate over a sequence (like a list, tuple, or string).
python
# Syntax of for loop for variable in sequence:
# code to run for each element in the sequenceExample 1: Say “As-Salaam-Alaikum" to each friend in a list of friends.
python
friends = ["Ahmad", "All", "Hassan"]
for friend in friends:
print("As-Salaam-Alaikum", friend)