The For and ForEach lesson introduces the concept of loops, which are bits of code that repeat a series of instruction as long as the condition evaluates to true. A for loop tells PHP three things: where to start the loop, where to end the loop , and what to do to get to the next iteration of the loop. For example, in the following code, $i is assigned the value of 2, and while $i is less than 11, the loop will add 2 to the value of $i each time the loop executes It will output the numbers 2, 4, 6, 8, and 10 and then stops.

For loops are useful for running the same code multiple times, especially when the amount of iterations is known. When the amount of iterations is not known, or when you are trying to display all of the elements in an array, a foreach loop can be used. For example, in the following code, the foreach loop will continue to run while words in the array remain. It will continue to loop until each word has been printed, which will result in the output "I'm learning PHP!"
