Loop
A loop is a program or script that repeats the same instructions or processes the same information over and over until receiving the order to stop. If not handled properly, a loop can cause the computer to become slower as it becomes overwhelmed with repeating the same steps in an endless loop.
Batch file loop
Below is a basic example of a loop in a batch file.
:BEGIN Echo Here is an endless loop! GOTO BEGIN
How do I break out of a loop?
When writing a loop, a condition should be part of the loop that allows the computer to escape from the loop. For example, if a loop was created that counted to 100 by incrementing a value of a variable. A condition should be made that if that variable is greater than or equal to 100, the loop is exited. Below is an example of a do loop doing this function.
my $count = 0; do { print "$count\n"; $count++; } until ($count >= 100);
If the computer is stuck in an endless loop, the user must send a signal interrupt. On a PC, this is done with the Ctrl+C shortcut.
Other types of loops
Below are examples of common types of loops in many programming languages. Visit each of these pages for additional information and examples about each loop.
Control statement, Endless loop, Feedback, Goto, Iteration, Loop device, Programming terms, Repeat counter, Repetition, STP