For loops combine variable initialization, condition checking, and incrementing into one line, cutting down the code you'd need in a while loop. The example prints Hello 0, 1, 2, 3, 4 in fewer lines than the equivalent while loop version.
Chapters
Hello again, I'm here to teach you the for, for PHP. For is basically like a while loop, only it's much more simple. Let's take a look at one. Starts out like a while loop, you do for, except for you— it works like this, you declare your variable. You see if the variable is equal to something, or less than, or more than, or, or and equals, whatever. And then you do an action every time for is run. So basically, basically, uh, a while loop will have to have a variable out here, and then we'll have to say that variable equals this, and then we'll have to— this part would be in the while loop, and then down here you would have this part. But instead of wasting those 3 lines, or the extra 2 lines, we can use our for. Which puts it all into one little line. And as we save that, we can see it outputs just like a while loop. Hello 0, 1, 2, 3, 4. Alright. That's basically all there is to it. Uh, just, yeah.