lukmanunindra

Home » Web 2 » Pertemuan 5 PHP

Pertemuan 5 PHP

Penggunaan Pengulang di program PHP

<?php
/* Cara 1 */
echo “Contoh 1 <br>”;
for ($i = 1; $i <= 10; $i++) {
echo $i;
}
echo “<br>”;

/* Cara 2 */
echo “Contoh 2 <br>”;
for ($i = 1; ; $i++) {
if ($i > 10) {
break;
}
echo $i;
}
echo “<br>”;

/* Cara 3 */
echo “Contoh 3 <br>”;
$i = 1;
for (; ; ) {
if ($i > 10) {
break;
}
echo $i;
$i++;
}
echo “<br>”;

/* Cara 4 */
echo “Contoh 4 <br>”;
for ($i = 1, $j = 0; $i <= 10; $j += $i, print $i, $i++);
?>

Advertisements
%d bloggers like this: