For loops allow you to do something a certain number of times in their most basic forms;
They take on the form:

for(initial_expression; test_expression; change_expression){

This is equivalent to a while statement that looks like


This for loop will print the numbers 1 through 100 on separate lines;

for($i=1; $i<=100; $i++){
   print "$i\n";
First the variable is set to 1, then it is tested to see if it is less than or equal to 100. Then it is printed. Then the change expression is evaluated and $i is incremented by 1. Then the text expression is evaluated again since $i is equal to 2 it is less than or equal to 100 so the loop is repeated until 100 is printed, $i is incremented to 101, $i is no longer less than or equal to 100 so the for loop is finished.

Now for foreach loops