Pemrograman PHP 6

Struktur Perulangan (LOOPING)

 

Struktur FOR <<< for.php >>>

 

<!doctype html public “-//W3C//DTD HTML 4.0 //EN”>

<html>

<head>

<title>STRUKTUR PERULANGAN</title>

</head>

<body>

<h1>Latihan FOR</h1>

<?

$awal = 1;

$akhir = 10;

echo”Nilai Awal = $awal <br><p>”;

for($angka = $awal ; $angka <= $akhir ; $angka++)

{

echo”Angka = $angka <br>”;

}

?>

</body>

</html>

 

Latihan WHILE <<< while.php >>>

<!doctype html public “-//W3C//DTD HTML 4.0 //EN”>

<html>

<head>

<title>STRUKTUR PERULANGAN</title>

</head>

<body>

<h1>Latihan While</h1>

<?

$angka = 1;

$akhir = 10;

echo”Nilai Awal = $angka <br><p>”;

while($angka < $akhir)

{

echo”Angka = $angka <br>”;

$angka++;

}

?>

</body>

</html>

 

 

 

 

 

Latihan DO-WHILE <<< dowhile.php >>>

<!doctype html public “-//W3C//DTD HTML 4.0 //EN”>

<html>

<head>

<title>STRUKTUR PERULANGAN</title>

</head>

<body>

<h1>Latihan Do-While</h1>

<?

$angka = 1;

$akhir = 10;

echo”Nilai Awal = $angka <br><p>”;

do

{

echo”$angka &nbsp;”;

$angka++;

}

while($angka < $akhir);

?>

</body>

</html>

 

Penggunaan Pada Form <<< tanggal.php >>>

<!doctype html public “-//W3C//DTD HTML 4.0 //EN”>

<html>

<head>

<title>Perulangan FOR pada Form</title>

</head>

<body>

<h1>Contoh FOR pada Form</h1><br><p>

Pilih Tanggal : &nbsp;

<select name = tanggal>

<?

for($tanggal = 1 ; $tanggal <= 31 ; $tanggal++)

{

echo”<option value = $tanggal>$tanggal</option>”;

}

?>

</select>

</body>

</html>

 

 

 

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s