TalentJR

Lesson 4

For Loops

Iterate over sequences

1What is a For Loop?✨

A for loop is a way to repeat actions in Python! It lets you run a block of code multiple times, which is super useful when you want to work with lists or ranges of numbers.

2Why Use For Loops?🎯

  • ✓ Save time by automating repetitive tasks
  • ✓ Easily go through items in a list
  • ✓ Make your programs more efficient
  • ✓ Improve your problem-solving skills

3Basic Structure of a For Loop💡

Here’s how a simple for loop works:

💻 code
for number in range(5):
    print(number)

This will print numbers from 0 to 4, one on each line!

4Looping Through a List🚀

You can also use for loops to go through items in a list:

💻 code
fruits = ["apple", "banana", "cherry"]
for fruit in fruits:
    print(fruit)

This code will print each fruit in the list!

5Counting with For Loops🔍

You can use for loops to count or sum up numbers. Check this out:

💻 code
total = 0
for number in range(1, 6):
    total += number
print("Total:", total)

This adds numbers from 1 to 5 and shows the total!

6Creating a Simple Countdown⭐

You can even create fun programs like a countdown:

💻 code
for count in range(10, 0, -1):
    print(count)
print("Blast off!")

7This will count down from 10 to 1, and then say "Blast off!"🧩

🎯 Practice Challenges

Master For Loops by completing all 3 difficulty levels

🟢 EASY

For Loops - Easy Challenge

Start with the basics. Perfect for beginners!

🟡 MEDIUM

For Loops - Medium Challenge

Get more challenging. Build your confidence!

🔴 HARD

For Loops - Hard Challenge

Master this concept. Prove your skills!

🏆 Study a lesson for 2+ minutes to earn +10 TalentJR Points a day. Badges, certificates & prizes →

Ready to Master For Loops? 🚀

Complete the challenges, take the quiz and keep your learning streak going!