Lesson plan

For Loops & Nested Loops

Students explore for loops and nested loops in MakeCode through tiered tutorials and then apply their coding skills to design pixel art in Minecraft.

For Loops & Nested Loops
Ages
Ages 8-18
Essential question

How do for loops and nested loops help programmers automate repetitive tasks and create complex designs efficiently?

Overview

Repetition is a core concept in computer science. When programmers need an action performed repeatedly, writing the same instructions over and over creates clutter and inefficiency. For loops and nested loops give students the ability to execute sequences of commands multiple times or run repeating patterns across two dimensions with clean, concise code.

In this lesson, learners access the MakeCode editor within Minecraft Education using their choice of visual blocks, JavaScript, or Python. After working through tiered exercises that involve spawning animals, directing the Agent to farm carrots, and constructing buildings, students inspect pixel art examples in the downloadable world and program their own pixel art creations.

Learning objectives

By the end of this lesson students will be able to:

  • Explain how a for loop repeats code a specific number of times.
  • Construct nested loops to repeat actions within an existing loop.
  • Program Minecraft actions using for loops in Blocks, JavaScript, or Python.
  • Create an original piece of pixel art in Minecraft using loop structures.

Blocks and items used in this lesson

Key vocabulary

For Loop
A programming structure that repeats a set of code instructions a specific number of times.
Nested Loop
A loop placed entirely inside the body of another loop.
Agent
A programmable companion robot in Minecraft that can build, farm, and navigate.
Pixel Art
Art made by placing individual colored blocks in a grid pattern to represent an image.

Before class

Lesson sequence

Suggested timing: about 60 minutes in total.

  1. Warm-up & Real-World Repetition10 min

    Ask students to name things they repeat daily, such as walking, eating, or breathing. Ask what happens when a song is set to repeat, highlighting that it restarts from the beginning. Discuss why programmers repeat code in Minecraft, such as running identical actions in different places.

  2. Tiered Coding Tutorials30 min

    Direct students to choose their preferred language (Blocks, JavaScript, or Python) and work through tutorials suited to their skill level:

    • Tutorial 1 (Novice, 5 min): Use events and for loops to spawn animals.
    • Tutorial 2 (Intermediate, 10 min): Program the Agent using for loops to plant carrots on a farm.
    • Tutorial 3 (Expert, 15 min): Construct a house using for loops.
  3. Pixel Art Design Challenge15 min

    Direct students to explore pixel art examples displayed inside the downloadable world. Students then design and code their own pixel art (such as a creeper face) by writing code with for loops and nested loops to place blocks across rows and columns.

  4. Review & Knowledge Check5 min

    Gather the class to reinforce key programming principles. Have students explain what a for loop does, what makes a loop nested, and why using loops is preferable to retyping code.

Assessment: success criteria

  • Student accurately defines a for loop as code that repeats a specific number of times.
  • Student identifies a nested loop as a loop placed inside another loop.
  • Student completes at least one coding tutorial using loops in Blocks, JavaScript, or Python.
  • Student writes functioning code using loops to generate a pixel art design in the world.

Differentiation

Support

Allow students to focus on visual block coding during the Novice animal-spawning tutorial before trying Agent commands.

Stretch

Prompt advanced students to write their house-building or pixel art code in JavaScript or Python using multi-level nested loops.

Knowledge check

5 questions to check understanding after the lesson. Tap an answer to see if it is right; the score appears at the end.

  1. 1What does a for loop do in computer programming?

  2. 2What is a nested loop?

  3. 3In the intermediate tutorial, what does the student program the Agent to do?

  4. 4What creative task are students asked to complete during the educational application section?

  5. 5Which three coding languages can learners choose from in the MakeCode editor for this lesson?

Resources

Part of the Coding Tutorials curriculum

This is lesson 6 of 9 in Coding Tutorials.

  1. Unit 2: Events
  2. Conditional Loops
  3. Conditionals
  4. Events
  5. Events in Programming
  6. For Loops & Nested Loops
  7. Functions
  8. Sequencing
  9. Variables

Frequently Asked Questions

Can students work through this lesson if they have no text-based coding experience?

Yes. The MakeCode editor allows students to complete all tutorials using visual drag-and-drop blocks before attempting JavaScript or Python.

How long does it take for a class to finish all the activities?

Completing all three tutorials alongside the pixel art application takes approximately one hour in total.

Do students have to complete all three tutorials?

No. Students can either select the single tutorial that fits their experience level or work through all three in sequence before moving to the art challenge.

Adapted from For Loops & Nested Loops by Minecraft Education on Minecraft Education, last updated Feb 4, 2025. This classroom version, the timings and the quiz were written by 9Minecraft Education.

You May Also Like

9Minecraft Education is an independent teaching resource and is not affiliated with Mojang or Microsoft. Lesson plans here are our own classroom-ready adaptations; each one links to the original resource and credits its author. © 2026 9minecraft.net