Hi everyone!
As you see we took a bit of a break from looping to learn about functions. Now we will go back to looping and learn two more types!
Let’s begin!
We will start with the For Loop. We use the for loop when we know how many times you want it to run.
The general format for the for loop looks like the following:
for(starting value; ending condition; increment){
statements go here;
}
What does each one mean?
Starting value – The variable that your function starts at. Usually 0 or 1.
Ending condition – A statement that will set your ending value. As long as this statement is true, your statements will keep repeating.
Increment – A statement that increments your counter.
Let’s do an example to understand this better.
for($x=1;$x<=3;$x++) { echo “$x. Smile!
”; }
The output for this will be as follows:
1. Smile!
2. Smile!
3. Smile!
Here is a video you can watch and try to do an example of writing out the numbers from one to ten step by step.
Enjoy and good luck!
See you next time!