Programming Basics
What Is a Loop in Programming?
A loop repeats a block of code, either a set number of times or while a condition stays true, so you do not have to write the same code twice.
Definition
A loop runs the same block of code several times. It saves you from writing repeated lines and lets a program handle any number of items, such as every row in a file.
The two main kinds are the for loop, which goes through a sequence or a counted range, and the while loop, which repeats as long as a condition is true.
How it works
Each pass through the loop is called an iteration. break leaves the loop early, and continue skips to the next iteration.
A while loop must change something that eventually makes its condition false. Otherwise it never ends, which is called an infinite loop.