Thursday, November 7, 2013

FOR Statement in PHP

FOR WHILE statement similar to this which has the following syntax

for (counter initialitation; requirement; increment/decrement counter)
{
  statement;

}

To clarify the understanding of the FOR, the following is an example of the code for to produce a display similar to the previous example while (about the amount of brush and price). Compare this to the previous code sample while.

example:
<?
$harga_sikat = 1500; 

echo "<table border=\"1\" align=\"center\">";
echo "<tr><td><b>Jumlah Sikat</b></td>";
echo "<td><b>Harga</b></td></tr>";
for ($jumlah_sikat = 10; $jumlah_sikat <= 100; $jumlah_sikat+=10)
{
  echo "<tr><td>";
  echo $jumlah_sikat;
  echo "</td><td>";
  echo "Rp. ".$harga_sikat * $jumlah_sikat;
  echo "</td></tr>";
}
for ($jumlah_sikat = 10; $jumlah_sikat <= 100; $jumlah_sikat+=10)
{
  echo "<tr><td>";
  echo $jumlah_sikat;
  echo "</td><td>";
  echo "Rp. ".$harga_sikat * $jumlah_sikat;
  echo "</td></tr>";
}
 
 

No comments:

Post a Comment