For Loops - Repeating Actions

For loops repeat actions for each item in a sequence (like a list). Instead of writing the same code many times, you write it once and say 'do this for each item'. The loop variable (like 'item' or 'i') takes each value one by one.

# For loops examples
# Example 1: Simple counting
print("Counting from 1 to 5:")
for number in range(1, 6):  # 1 to 5 (6 is not included)
    print(number)

# Example 2: Looping through a list
fruits = ["apple", "banana", "cherry", "date"]
print("\nMy favorite fruits:")
for fruit in fruits:
    print("I love", fruit)

# Example 3: Multiplication table
print("\nMultiplication table for 5:")
for i in range(1, 11):  # 1 to 10
    result = 5 * i
    print(f"5 x {i} = {result}")

# Example 4: Looping with index
colors = ["red", "green", "blue", "yellow"]
print("\nColors with their positions:")
for index, color in enumerate(colors):
    print(f"Position {index}: {color}")

# Example 5: Building a pattern
print("\nBuilding a pattern:")
for i in range(5):
    print("*" * (i + 1))