PLEASE RELOAD
Simple Uses for Loop



A simple loop can become a webpage line. If you have an image on your page for your visitors to click, you might want a line of those images as a separator. A loop is perfect for that.

This is an image I use as a link.   Star
If the width of the star is 20, let's put ten of them across to make a line of 200 pixels.

starstarstarstarstarstarstarstarstarstar



Here's the code for it:

<?

$times = 10;
$x = 0;
while ($x < $times)
{
echo "<img src=/artcode/star.gif height= 20 width=20 alt=star border=0 />";
++$x;
}
?>



You can loop html also as in this example. No quote marks are used inside the html.



Here's the code for it:

<table cellpadding=0 cellspacing=0 border=1>
<tr>
<?
$times = 10;
$z = 0;
while ($z < $times)
{
echo "<td bgcolor=red width=10 height=10></td> <td bgcolor=blue width=10 height=10></td>";
++$z;
}
?>
</tr></table>



You can loop both as in this example.

star star star star star star star star star star


Here's the code for it:

<table cellpadding=0 cellspacing=0 border=1>
<tr>
<?
$times = 10;
$Q = 0;
while ($Q < $times)
{
echo "<td><img src=/artcode/star.gif height= 20 width=20 alt=star border=0 /></td> <td bgcolor=blue width=20 height=20></td>";
++$Q;
}
?>
</tr></table>




Back SiteMap