Level 4: For Loops - IncrediCoders/Python1 GitHub Wiki

SW_avatar7

SideWinder added this page on June 6, 2025

Hi Paul, and I guess whoever else is reading this! I wrote you this bonus article about For Loops, because I'm like the best friend ever!

In addition to this bonus article, you can find another bonus article on topics I showed you in Level 4: Elif and States

Learn about For Loops

A for loop helps you repeat something a specific number of times. Instead of writing the same line of code again and again, a for loop does it for you automatically.

It’s like saying, “Write your name on the paper 5 times,” and the computer listens. Super helpful for patterns, animations, or checking lots of things at once.

Why For Loops Matter

For loops make your code shorter and smarter. Instead of copying and pasting, you write one loop that handles everything.

Python Example

Python uses the for keyword with something called a range() to tell the loop how many times to repeat.

Scenario: Paul Python wants to print “Hello!” 3 times.

for i in range(3):
    print("Hello!")

This means:

  • range(3) tells Python to run the loop 3 times.
  • Each time, it prints "Hello!"

Comparing Programming Languages

All programming languages have for loops, but they use different styles to say how many times to repeat something.

Let's look at this example: We want to print the word “Hi” 5 times.

Python

for i in range(5):
    print("Hi")

Java

for (int i = 0; i < 5; i++) {
    System.out.println("Hi");
}

C#

for (int i = 0; i < 5; i++) {
    Console.WriteLine("Hi");
}

What’s the Difference?

  • Python uses range() and is super easy to read.
  • Java and C# need to create a counting variable (int i = 0) and update it.
  • All three languages can repeat actions, but they just say it differently.

Learn More

TBD

Next Steps

Next, you can take on the two extra challenges to add to your Space Wars program and learn more! When you're done, you can move on to Level 5, the Creeper Chase!

Take the Challenges!

  1. Challenge 1: In this challenge, you are going to add sound to the game when projectiles are fired!

  2. Challenge 2: In this challenge, you are going to write code that will add asteroids to the game!

More Level 4 Resources

In addition to this Help page and the instructions for our Level 4 challenges, we also have Online Articles, a Learning Quiz, an Unplugged Activity, and a Rewards article:

  • Level 4: Online Articles - I made you a list of different web pages I found, which will help you learn more about creating the Space Wars program.

  • Level 4: Learning Quiz - I wrote some questions in case you want to quiz yourself about what you learned. Or you can teach others and quiz them!

  • Level 4: Unplugged Activity - I wrote this page with more details than what you saw in the book. You're going to recreate the SpaceWars game in person! You'll get a chance to review and practice key events and how they work with spaceships.

  • Level 4: Rewards - If you completed the Space Wars project, then you're welcome to check out this page as a reward. You can see some illustrations of me and learn more about who I am! You'll also find the Goth Award digital download, to show off your accomplishment!

Level 5

After you're completely done with Level 4 (did you do the challenges?), then it's time to move on to Level 5! While you read through Level 5 in your book, you can check out the resources from Intelli-Scents, as she teaches you how to build the Creeper Chase program:

I hope you had fun learning about space wars!

-- SideWinder