Now that we know how to compare one value to another we can learn another control structure.
We already saw how far each loop can be used to leap around an array running the same code multiple
times for each element of the array.
There's a simpler form of loop in P HP called A Wild loop while loop can be used to any code not just
to loop around and array a while loop simply runs code continuously while a condition is true.
This means that at some point inside the loop you need to change the condition to false.
Otherwise the loop would run forever.
Let's look at an example.
We'll start with a variable that contains an integer representing the month of the year.
Then I'll add a while loop with a condition that says a month is less than equal to 12.
Then in the while loops code block let's print out the value of the month followed by a comma as we
saw earlier.
Even though this variable contains an integer and when we try and can catinat it to a string.
Using the dot operator its value will be converted automatically to a string.
Finally will add one to the month variable like that.
If we missed this bit out the while condition would always be true and we'd have an infinite loop.
So let's see what happens when we run this code.
We get all the month's printed out from 1 to 12.
Let's go through what happened.
We start by assigning the value of one to the month variable.
Then the while loop starts by checking the value of the condition one is less than our equal to 12.
So the condition is true.
The while loops code book is executed.
Printing out the value of the month then incrementing its value.
Then the loop goes back to the top again checking the value of the condition.
The condition is still true so the code block is executed again.
This continues printing out the value and then incrementing it by one for each iteration of the loop
until it's incremented to 13.
When this happens the condition is false.
So the while loop stops and the script continues with whatever code comes after the while loop if any.