simpan program dengan nama struktur-while.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml/DTD/xhtml-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="on" lang="on">
<head>
<tittle>Praktikum 4.Perulangan</tittle><br>
<meta http-equiv="content-type" content="text/html; charsct=utf-8" />
<meta name="generator" content="Geany 0.20" />
</head>
<body>
<?php
$tinggi = 10 ;
$i = 0;
while ($i < $tinggi){
$j = 0;
while($j<=$i){
echo "*";
$j++;
}
echo "<br>";
$i++;
}
?>
</body>
</html>
maka outputnya sebagai berikut:
Praktikum 4.2 Percabangan do while
simpan program dengan nama struktur-do-while.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml/DTD/xhtml-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="on" lang="on">
<head>
<tittle>Praktikum 4.Perulangan</tittle><br>
<meta http-equiv="content-type" content="text/html; charsct=utf-8" />
<meta name="generator" content="Geany 0.20" />
</head>
<body>
<?php
$i=0;
do {
$j = 0;
while($j < $i){
echo "*";
$j++;
}
echo "<br>";
$i++;
}while($i<=10);
?>
</body>
</html>
maka outputnya sebagai berikut:
simpan program dengan nama cek-bilangan.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml/DTD/xhtml-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="on" lang="on">
<head>
<tittle>Praktikum 4.Perulangan</tittle><br>
<meta http-equiv="content-type" content="text/html; charsct=utf-8" />
<meta name="generator" content="Geany 0.20" />
</head>
<body>
<?php
$x = 100;
while ($x > 0){
if ($x % 2 ==0){
echo "$x adalah bilangan Genap";
}else{
echo "$x adalah bilangan <b>Ganjil</b>";
}
echo "<br>";
$x--;
}
?>
</body
</html>
maka outputnya sebagai berikut:
Praktikum 4.3 Perulangan for
simpan program dengan nama perulangan-for.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml/DTD/xhtml-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="on" lang="on">
<head>
<tittle>Praktikum 4.Perulangan</tittle><br>
<meta http-equiv="content-type" content="text/html; charsct=utf-8" />
<meta name="generator" content="Geany 0.20" />
</head>
<body>
<?php
$tinggi = 10;
$i = 0;
for ($i = 0 ; $i <= $tinggi ; $i++){
for ($j = 0 ; $j < $i ; $j++ ){
echo "*";
}
echo "<br>";
}
?>
</body>
</html>
maka outputnya sebagai berikut:
Tidak ada komentar:
Posting Komentar