Written by the Fiveable Content Team โข Last updated September 2025
Verified for the 2026 exam
Verified for the 2026 examโขWritten by the Fiveable Content Team โข Last updated September 2025
Definition
Loops are control structures in programming that allow you to repeatedly execute a block of code until a specified condition is met. They provide an efficient way to perform repetitive tasks without writing redundant code.
Related terms
While Loop: A while loop is an entry-controlled loop that continues executing as long as its condition remains true. It checks the condition before each iteration.
A for loop is also an entry-controlled loop, but it has three parts - initialization, condition, and increment/decrement. It's often used when we know exactly how many times we want the loop to run.
An infinite loop is a loop that continues indefinitely because its exit condition is never met. It can be unintentional and cause the program to hang or crash if not handled properly.