For loop in PHP
A loop is good to repeat the same steps over and over again.
First loop that I am going to cover is for loop. I am going to cover PHP for loop, but for loop is not available only in PHP, it is also available in other programming languages.
For loop accepts three steps.
First one is initialization of a loop variable. It is common to use lower case I or j as loop variables.
Second step is a condition until when the code inside of that loop is going to repeat.
Third step indicates a change of a change of a loop variable with each iteration of that loop. Common change values is to increase a loop variable by one or decrease it by one.
There is a danger of having an infinite loop, where this loop will increase its loop variable by one, however inside of that loop, that variable will be decreased by one.
Comments
Post a Comment