What are Loops?

Learn about loops, repeated patterns in code.

Jon Mattingly avatar
Written by Jon Mattingly
Updated over a week ago

In programming, loops are important to learn and understand how to use to be able to create dynamic programs that can do a lot of different things. Students will be introduced to loops in planet Aquatopia.

Definition: Loops are a programming element that repeat a portion of code a set number of times until the desired process is complete. Repetitive tasks are common in programming, and loops are essential to save time and minimize errors.

Real Life Example: We talked about ordering the steps correctly to make one PB and J. What if we need to make 500 peanut butter and jelly sandwiches for a school field trip? Instead of having to do the same, monotonous steps over and over again, we would likely prefer to just do it once and have it automatically repeated until 500 sandwiches were made.

Programming Application: When programmers write code, loops allow them to shorten what could be hundreds of lines of code to just a few.

This allows them to write the code once and repeat it as many times as needed, making it more likely for the program to run as expected.

In Kodable, students will identify where the code repeats and practice applying a set number of loops. 

In this example level, the same set of commands is used two times in a row-right, up, right, up. Instead of writing these commands three times, we use a loop and only have to write it once.

Why We Use Loops: Loops make code more manageable and organized. As we learn more about programming and writing complex programs, loops will be an important element to understand and use.

Did this answer your question?