Minecraft Education – Lesson 2

Using Loops to Repeat Actions

Objectives

Vocabulary


Part A – Basic Loop with player.say

Instead of copying the same line over and over, we can use a loop to repeat it.

Sample Code:

for i in range(5):
    player.say("This is message number " + str(i))

Discussion:


Part B – Building a Line of Blocks

Let’s build a straight line of blocks in front of the player.

Sample Code:

# Build a line of 10 stone blocks along the X-axis
for x in range(10):
    blocks.place(STONE, pos(x, 0, 0))

Try:


Part C – Building a Simple Wall (Nested Loops)

This example uses a loop inside a loop (nested loops) to build a wall.

Sample Code:

# Build a 10x3 wall (10 wide, 3 high)
for x in range(10):      # width
    for y in range(3):   # height
        blocks.place(BRICKS, pos(x, y, 0))

Discussion:


Extension Challenge

Modify the wall to create a doorway by skipping some blocks in the middle.

Hint: Use an if statement inside the loop, for example:

for x in range(10):
    for y in range(3):
        # Skip blocks at the center (doorway)
        if not (x == 4 or x == 5) or y > 1:
            blocks.place(BRICKS, pos(x, y, 0))

Due Date: December 3, 2025

Submit it to Google Classroom.
Save your file as PX_L02_lastname.png.