I will call you back again to another video lecture in PHP.
And in this video lecture I'll go ahead and tell you about for loop in PHP.
All right.
So we looked at a while loop and we have dealt with a do while loop.
Now let's go ahead and look at for loop.
So for loop is another loop system you can use to iterate through uh information in PHP.
So your program you can always use for loop or use while loop or do while loop.
Now let's go ahead and see.
This is a for loop.
And uh anything inside here is what I'm going to generate.
So now let's go ahead and say I have this while loop right in here.
And that you ask me why didn't I delete this while loop?
The reason why I left this while loop till now is because I want to use that to teach us about for loop,
because while loop is the same thing with for loop.
But if you are a beginner, you will be like why?
What is going on?
So just the same way and the same information, everything right in here is what we are going to use
to generate whatever we have at the output.
So in for loop we are going to write everything within the for loop system.
Then you go ahead and execute the program inside the for loop.
Now let's go ahead and see.
The very first thing we have here is the gradient variable.
And that is the first thing you do inside the for loop.
Go ahead and declare I want to say num equal to one.
You see that num equal to one.
And then you give the condition we set y null is less than or equal to ten.
So that is the next condition.
So the next thing after the condition in for loop is setting a condition.
And then you can have a semicolon at the end.
Because we have one more thing to go and that the next is setting that condition and the you go ahead
and give it a target.
So the target is that it's going to increment one here.
You're going to remove the semicolon at the end.
So just the sentence we have right in here declaring the variable.
Then set your conditions and uh giving it uh the target.
And that is you want this to always increment.
Always wanted to also decrement you.
And then now we go ahead and print out Norm.
I'll go ahead and copy this and put it right inside the for loop.
So now I want to delete the while loop.
And we have here.
Now let's go ahead and run this code and check it out.
So you see I run this code and I got exactly the same thing.
So if I go ahead and check this to change it to seven I'll run this code.
You can see I have 127.
So you can see that what we have is just exactly the same thing.
So for loop makes it so we clean easier and straightforward.
So that is why for loop is more preferable to so many people out there than other loop systems, but
none is better than the other.
You can actually use any one of your choice.
All right.
So let's go ahead and use this for loop to actually do some practices in PHP.
Let's go ahead and say we have this variable.
Or for goals settings and goals scored by different players.
All right.
Now we're going to do is to check an array.
So we're going to create an array of these goals by different players.
Let's say the first one score 95
2015 and 40 goals.
So we have this 12345 and six.
Our goal is to also be up to seven.
So let me see.
The next one is going to be dating goals.
Alright, now if I save this.
So this is an array of numbers.
Go ahead and place a semicolon at the end of this.
And we want to generate this array.
Want to print out these.
So how do we print this out.
So what we need to do right here is instead of all saying we have set this starting from one okay.
Now what we need is to set it to start from zero.
Because if you remember the time I taught you about array, I told you that the very first number here
is index zero okay.
And next one is index one.
And the next one is index two.
Uh index three, index four, index five and index six.
So let's go here to comments on this.
So that uh, we are not going to run into an error when we print that out.
All right.
Now I want to show you this.
And uh, we want to me start from index zero.
That means none is going to start from zero and not one.
Okay.
And then we are going to now print out the same none less than or equal to the array the variable name.
So the variable here is go.
Okay.
So you can actually copy this.
So that is what we are going to give the conditions.
So say this is counts.
So counts goes.
All right.
That is only going to print out.
And they're all good.
So we don't just echo the none we call the variable I.
We're going to insert the num right inside the variable.
So go ahead and say echo.
And then we're going to be index of the nome.
So the index of the nome is what we're going to insert right in there.
Because if we put the index 10123, it's going to print just one.
But we want everything to be printed out.
Now if we go ahead and run this and we say we have an error at a line 12 and it says undefined array
key seven.
So this is not an error right in there.
It's a go ahead and refresh this.
And uh there is no error there.
Only swirl.
And uh that is it.
Now if we go ahead and uh, say.
Let's say we want to print this less than the number, we can go ahead and refresh this.
And, uh, that is off.
So what happened right here is I said that this starts from zero, and then num should be less than
Down count.
That means is going to print from 0 to 13.
All right.
So we remove less than or equal to because this is not number.
It was actually given a count.
And that is why it was giving us an error right in there.
So now we removed less than or equal sign.
So it's going to just be less than sign okay.
So we can actually print from 9 to 18.
So if I take this to maybe if I want 67 uh, 23 I refresh this.
We can actually print that out.
You can see that.
So that is it adding is very interesting.
You can use this whole loop to iterate through, uh, arrays of numbers.
And that is very good.
So why not practice with that.
Check it out and play around it.
And if you have any questions, go ahead and use the question and answer section.
And I'm going to get back to you as soon as possible.
Thank you so much.
And I'm going to see you in the next video lecture.