PHP For


PHP For Repetition

As with other programming languages, PHP also provides the facility to perform repetition. One way is to use a For. Write this example below :


<html>
<head>
<title> Repetition </ title>
</ head>
<body>
<center>
<?
for ($count = 1; $count <= 10; $count++)
{
print ("This is line number : $count <br>");
}
?>
</ center>
</ body>
</ html>

If the script above is run it will appear as below.
This is line number : 1
This is line number : 2
This is line number : 3
This is line number : 4
This is line number : 5
This is line number : 6
This is line number : 7
This is line number : 8
This is line number : 9
This is line number : 10

At the time of line repetitions (which starts from for ($count = 1; $count <= 10; $count++)) is run for the first time, the value of $count is 1. Hence the top line is printed on the browser are:
This is line number 1
Repetition will continue to run as long as the value of $count is less than or equal to 10.

0 comments:

Post a Comment