|
|
|
Printing number from 1 to 50 by for loop |
We 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.
for( $i=1; $i<=10; $i++ )
{
echo $i;
echo "<br>";
}
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.
You can get more details on for loop here.
Here we have printed from 1 to 10 numbers, by changing the values inside the for loop you can print numbers starting from any value to ending at any value.
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.
Let us try with some simple examples.
| |
| Subscribe |
|
Submit your email address and receive
article and product notifications. Your email is safe with us.
|
|
|
|
|
|