SQL PHP HTML ASP JavaScript articles and free scripts to download
 

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.



Further readings
Introduction to PHP: How scripting languages work
PHP beginners guide
echo command & escape character for string outputs
Adding delay to the script execution time by using sleep function
Disabling a part of the code by using comments in PHP
Printing Numbers 1 to 50 to screen
PHP Info: Details on PHP script settings & installation at server end
PHP.ini file: PHP server configuration setting file for Edit or update
ini_get: PHP function to get configuration settings from php.ini file
ini_set: PHP function to change the configuration settings of php.ini file
PHP Version : What is the version of PHP running at the server
Installing PHP on windows server and IIS
Installing PHP5 on windows server and IIS
Setting up PHP in Windows Vista OS to run in IIS7 web server
Configuration of IIS7 to run PHP scripts with ISAPI module Extension directory of PHP to store dll files for windows












Post Comment This is for short comments only. Use the forum for more discussions.
Name
Email( not to be displayed)Privacy Policy
1+2=This is to prevent automatic submission by spammers. Please enter the result of the sum as asked


Join Our Email List
Email:  
For Email Newsletters you can trust
Basics
PHP Sections