Perulangan di dalam PHP

Struktur perulangan dalam PHP menggunakan while, do..while dan for, format penulisannya :
while (condition) {
statement;
}
demowhile.php
<?php
$i=1;
while($i<=5)
{
echo “bilangan ke : ” . $i . “<br />”;
$i++;
}
?>
do
{

statement;
} while (condition);

demodo.php
<?php
$i=0;
do
{
$i++;
echo “bilangan ke ” . $i . “<br />”;
}
while ($i<5);
?>
for (initialization; condition; increment)
{
statement;
}

demofor.php
<?php
for ($i=1; $i<=5; $i++)
{
echo “Hallo….!<br />”;
}
?>

Iklan

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s