Step 1

Explaining the for loop


In the last project, we combined both loops and if statements to create a very useful farming program.

In this project we will combine the infinite loop with a new type of conditional loop, the for loop to make a program that shoots out lava wherever we walk!

Before we get started, try out this small bit of test code to see what exactly a for loop does.

A for loop takes a variable, here it is “i”, and modifies it until it reaches the limit we set. It loops until it reaches the limit, once it does, it stops.

Here, we tell for loop that we want it to go from 1 to 3, and when we test it out, we see it does just that! As the loop progresses, the value for “i” changes.