Introduction to Programming

Introduction to Loops

Lesson 8: Loops

What is a Loop?

Imagine you had to write 'I will not run in the hallway' 100 times. That would take forever! In programming, when we need to repeat an action multiple times, we use loops instead of writing the same blocks over and over.

A loop is a programming structure that repeats a set of instructions either a specific number of times or until a certain condition is met.

Why Do We Use Loops?

  • To avoid writing the same code repeatedly.
  • To perform a task a specific number of times.
  • To keep a program running until something happens.
  • To process each item in a list or sequence.

Types of Loops in PictoBlox

Types of Loops in PictoBlox

LoopFound InWhen to Use It
ForeverControlWhen you want something to repeat indefinitely
Repeat (n)ControlWhen you want to repeat exactly n times
Repeat Until (condition)ControlWhen you want to repeat until a condition becomes true
PictoBlox Control palette showing Forever, Repeat, and Repeat Until loop blocks

The Forever Loop

The Forever loop repeats its contents indefinitely until the program is stopped. It is commonly used for things that should always be running, like checking for key presses or keeping a sprite moving.

The Repeat (n) Loop

The Repeat (n) loop runs its contents a fixed number of times. When we drew shapes earlier, we used Repeat 4 to draw a square and Repeat 3 to draw a triangle.

Loops are one of the most fundamental and powerful concepts in programming. Almost every real program uses loops in some form!

Subscribe to our newsletter.

Get updates to news and events.