CurriculumGrades 3-5Computer Science

Programs with loops, events, and debugging

Aligned to CSTA-AP — CSTA K-12 Computer Science Standards.

What this lesson teaches

A loop tells a program to repeat an action so you do not have to copy the same step over and over. An event makes something happen in response to an action, like a key press or a click. When a program does not work right, you debug it: test it, find what went wrong, fix it, and test again. Mistakes are a normal part of coding.

Worked example

Imagine telling a robot to clap 10 times. Instead of writing clap ten times, you write a loop: repeat 10 times, clap. If it claps 9 times, you debug by checking your number, find it said 9, and change it to 10.

Practice questions

  1. What does a loop let you avoid doing?
  2. Give an example of an event that could start a program.
  3. If a program runs but does the wrong thing, what are the steps to debug it?

Watch the lesson

Every lesson comes with a video taught in English and Spanish — the same video the QR code in the printed workbook opens.

▶ Watch this lesson

En español

Programas con ciclos, eventos y depuración

Un ciclo le indica a un programa que repita una acción para que no tengas que copiar el mismo paso una y otra vez. Un evento hace que algo ocurra en respuesta a una acción, como presionar una tecla o hacer clic. Cuando un programa no funciona bien, lo depuras: lo pruebas, encuentras qué salió mal, lo corriges y lo pruebas de nuevo. Los errores son una parte normal de programar.

Ejemplo: Imagina decirle a un robot que aplauda 10 veces. En lugar de escribir aplaude diez veces, escribes un ciclo: repite 10 veces, aplaude. Si aplaude 9 veces, lo depuras revisando tu número, encuentras que decía 9 y lo cambias a 10.

Teach this lesson today

An AI tutor that guides with questions instead of just giving answers — all K–12 core subjects, every child in the family.

Start free — no card required