Printing number from 1 to 50 by for loopWe can print numbers from 1 to 10 by using for loop. You can easily extend this program to print any numbers from starting from any value and ending on any value.
The echo command will print the value of $i to the screen. In the next line we have used the same echo command to print one html line break. This way all numbers will be printed in one new line.
For loop is used when we know exactly how many times the looping is required. Here no condition is set for looping. While loops are used for conditional looping.
What happens when we keep a condition which the loop can never meets?
Inside the loop each time we are resetting the value of $i to 5 , so it can never reach value of 10 to exit the loop.
Output is here.
Server stops the execution of the script after 30 seconds. This value of 30 seconds is set at php.ini file, we can change this upper limit of execution time by using ini_set() function.
Just add this line to the above code.
Now script execution will stop after 2 seconds
This article is written by plus2net.com team.