Perl offers the common loop structures for, foreach, and while along with do..while and do..until.
A for loop is used to parse a block of code X number of iterations. This example will loop though and execute the DO SOMETHING block each time through incrementing the value of $i. As long as $i is less than 10 the code block will be executed.
The foreach is used to loop through a set of values. The foreach loop is commonly used to loop through the values of an array or hash. This example will set a list of values into @array then loop through and print each value.
The while loop will execute a code block as long as a condition is true. In the following as long as $i is less than 20 the code block will execute.
The do..while loop is the same as a while loop except the conditional is evaluated after the code block is executed. This is favorable if you want the code block to execute at least once.
The do..until loop is the opposite of a do..while loop. The do..until loop executes the code block until the condition is true.
do {