Header_blog

Coding Education

4 min read

What Is a Loop (Perulangan) in Programming?

Published: 10.07.2026·Updated: 22.07.2026
Bayu Nugraha

Bayu Nugraha

Children's Coding Specialist

What Is a Loop (Perulangan) in Programming?

A loop (perulangan) is a programming instruction that tells the computer to repeat a single command or block of code automatically, many times over, without having to write the same command again and again. Loops make programs shorter, cleaner, and much faster to build.

Table of Contents

Types of Loops

Two kinds of loop are most common. A for loop is used when the number of repetitions is known in advance, such as "repeat exactly 10 times." A while loop is used when the repetition should continue as long as a condition stays true, such as "keep running while the player's score is under 100." Both stop the moment their task is finished.

In Scratch, a child can see how a loop works through the "repeat 10" block: one small block replaces ten separate commands. Imagine drawing a square. Without a loop, a child has to write "move, then turn" four separate times. With a repeat 4 block, one command is enough, and the character on screen draws all four sides on its own. In a large program, a single loop can save hundreds of lines of code.

How to Write a Loop in Scratch and Python

To write a loop, you wrap the commands you want to repeat inside a loop block and tell it how many times to run. In Scratch a child drags a repeat 4 block and drops the "move" and "turn" blocks inside it, and the sprite draws a square on its own. In Python the same idea looks like for i in range(4): with the repeated line indented underneath. A while loop runs a little differently: while score < 100: keeps going until the score reaches 100. The pattern is the same in every language, so once a child gets it in Scratch, moving to Python feels familiar.

Why It Matters for Kids

Loops are one of the first concepts taught in coding because they train children to think efficiently: to spot a repeating pattern and simplify it. This pattern-spotting skill is useful not only at the computer, but also in math and everyday logic. In the Algonova coding course, children learn loops through Scratch projects they can run and play with right away.

Try a free class and watch your child build their first program using loops.