Praktikum 3.1 Struktur IF
<!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”>
“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 3. Struktur Kontrol</tittle>
<meta http-equiv=”content-type” content=”text/html; charsct=utf-8″ />
<meta name=”generator” content=”Geany 0.20″ />
</head>
<tittle>Praktikum 3. Struktur Kontrol</tittle>
<meta http-equiv=”content-type” content=”text/html; charsct=utf-8″ />
<meta name=”generator” content=”Geany 0.20″ />
</head>
<body>
<?php
$stok_roti = 100;
<?php
$stok_roti = 100;
if($stok_roti <= 50){
echo ‘<script language= “javascript”> alert (“Stock Roti sudah menipis”)</script>’;
}
echo ‘<script language= “javascript”> alert (“Stock Roti sudah menipis”)</script>’;
}
?>
<body>
</html>
Output :
Akan Muncul message box jika sudah di bawah 100
<!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”>
“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 3. Struktur Kontrol</tittle>
<meta http-equiv=”content-type” content=”text/html; charsct=utf-8″ />
<meta name=”generator” content=”Geany 0.20″ />
</head>
<tittle>Praktikum 3. Struktur Kontrol</tittle>
<meta http-equiv=”content-type” content=”text/html; charsct=utf-8″ />
<meta name=”generator” content=”Geany 0.20″ />
</head>
<body>
<?php
$stok_roti = 40;
<?php
$stok_roti = 40;
if($stok_roti <= 50){
echo ‘<script language= “javascript”> alert (“Stock Roti sudah menipis”)</script>’;
}
echo ‘<script language= “javascript”> alert (“Stock Roti sudah menipis”)</script>’;
}
?>
<body>
</html>
OUTPUT :
Akan Muncul Message Box Untuk Stok baju dan celana dibawah 10
<!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”>
“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></tittle>
<meta http-equiv=”content-type” content=”text/html; charsct=utf-8″ />
<meta name=”generator” content=”Geany 0.20″ />
</head>
<body>
<?php
$stock_baju= 8;
$stock_celana =8;
<tittle></tittle>
<meta http-equiv=”content-type” content=”text/html; charsct=utf-8″ />
<meta name=”generator” content=”Geany 0.20″ />
</head>
<body>
<?php
$stock_baju= 8;
$stock_celana =8;
if($stock_baju <=10 && $stock_celana <=10){
echo ‘<script language= “javascript”> alert (“stock baju dan celana sudah menipis”)</script>’;
}
echo ‘<script language= “javascript”> alert (“stock baju dan celana sudah menipis”)</script>’;
}
?>
<body>
</html>
</html>
OUTPUT :
menentukan bilangan genap dan ganjil
<!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”>
“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 3. Struktur Kontrol</tittle>
<meta http-equiv=”content-type” content=”text/html; charsct=utf-8″ />
<meta name=”generator” content=”Geany 0.20″ />
</head>
<tittle>Praktikum 3. Struktur Kontrol</tittle>
<meta http-equiv=”content-type” content=”text/html; charsct=utf-8″ />
<meta name=”generator” content=”Geany 0.20″ />
</head>
<body>
<?php
$angka1 = 7;
<?php
$angka1 = 7;
if($angka1 % 2 == 1){
echo ‘<script language= “javascript”> alert (“7 adalah Bilangan Ganjil!!!”)</script>’;
}
echo ‘<script language= “javascript”> alert (“7 adalah Bilangan Ganjil!!!”)</script>’;
}
?>
<body>
</html>
OUTPUT :
struktur-if-else
<!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”>
“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 3. Struktur Kontrol</tittle>
<meta http-equiv=”content-type” content=”text/html; charsct=utf-8″ />
<meta name=”generator” content=”Geany 0.20″ />
</head>
<tittle>Praktikum 3. Struktur Kontrol</tittle>
<meta http-equiv=”content-type” content=”text/html; charsct=utf-8″ />
<meta name=”generator” content=”Geany 0.20″ />
</head>
<body>
<?php
$umur = 12;
<?php
$umur = 12;
if (($umur < 20) && ($umur > 10)){
echo ‘saya masih remaja’;
}
echo ‘saya masih remaja’;
}
?>
</body>
</html>
OUTPUT NYA :
struktur-if-else-if
<!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”>
“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 3. Struktur Kontrol</tittle>
<meta http-equiv=”content-type” content=”text/html; charsct=utf-8″ />
<meta name=”generator” content=”Geany 0.20″ />
</head>
<tittle>Praktikum 3. Struktur Kontrol</tittle>
<meta http-equiv=”content-type” content=”text/html; charsct=utf-8″ />
<meta name=”generator” content=”Geany 0.20″ />
</head>
<body>
<?php
$bulan_lahir = 6;
<?php
$bulan_lahir = 6;
if ($bulan_lahir == 1){
echo ‘Anda lahir di bulan januari’;
}else if ($bulan_lahir == 2){
echo ‘Anda lahir di bulan Februari’;
}else if ($bulan_lahir == 3){
echo ‘Anda lahir di bulan Maret’;
}else if ($bulan_lahir == 4){
echo ‘Anda lahir di bulan April’;
}else if ($bulan_lahir == 5){
echo ‘Anda lahir di bulan Mei’;
}else if ($bulan_lahir == 6){
echo ‘Anda lahir di bulan Juni’;
}else if ($bulan_lahir == 7){
echo ‘Anda lahir di bulan Juli’;
}else if ($bulan_lahir == 8){
echo ‘Anda lahir di bulan Agustus’;
}else if ($bulan_lahir == 9){
echo ‘Anda lahir di bulan September’;
}else if ($bulan_lahir == 10){
echo ‘Anda lahir di bulan Oktober’;
}else if ($bulan_lahir == 11){
echo ‘Anda lahir di bulan November’;
}else if ($bulan_lahir == 12){
echo ‘Anda lahir di bulan Desember’;
}else{
echo ‘Bulan yang anda masukkan salah’;
}
echo ‘Anda lahir di bulan januari’;
}else if ($bulan_lahir == 2){
echo ‘Anda lahir di bulan Februari’;
}else if ($bulan_lahir == 3){
echo ‘Anda lahir di bulan Maret’;
}else if ($bulan_lahir == 4){
echo ‘Anda lahir di bulan April’;
}else if ($bulan_lahir == 5){
echo ‘Anda lahir di bulan Mei’;
}else if ($bulan_lahir == 6){
echo ‘Anda lahir di bulan Juni’;
}else if ($bulan_lahir == 7){
echo ‘Anda lahir di bulan Juli’;
}else if ($bulan_lahir == 8){
echo ‘Anda lahir di bulan Agustus’;
}else if ($bulan_lahir == 9){
echo ‘Anda lahir di bulan September’;
}else if ($bulan_lahir == 10){
echo ‘Anda lahir di bulan Oktober’;
}else if ($bulan_lahir == 11){
echo ‘Anda lahir di bulan November’;
}else if ($bulan_lahir == 12){
echo ‘Anda lahir di bulan Desember’;
}else{
echo ‘Bulan yang anda masukkan salah’;
}
?>
</body>
</html>
OUTPUT NYA :
struktur if bersarang
<!DOCTYPE html PUBLIC “//W3C//DTD XHTML 1.0 Strict//EN”
“http://www.w3.org/TR/xhtml1/DTD/xhtml1strict.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml” xml:lang=”en” lang=”en”>
“http://www.w3.org/TR/xhtml1/DTD/xhtml1strict.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml” xml:lang=”en” lang=”en”>
<head>
<tittle>Praktikum 3. Struktur Kontrol</tittle>
<meta http-equiv=”content-type” content=”text/html; charsct=utf-8″ />
<meta name=”generator” content=”Geany 0.20″ />
</head>
<tittle>Praktikum 3. Struktur Kontrol</tittle>
<meta http-equiv=”content-type” content=”text/html; charsct=utf-8″ />
<meta name=”generator” content=”Geany 0.20″ />
</head>
<body>
<?php
$tanggal_lahir = 16;
$bulan_lahir = 6;
<?php
$tanggal_lahir = 16;
$bulan_lahir = 6;
if($bulan_lahir == 1){
if($tanggal_lahir <= 20)
echo ‘Anda Berzodiak <b>CAPRICORN</b>’;
else
echo ‘Anda Berzodiak <b>AQUARIUS</b>’;
}else if($bulan_lahir == 2){
if($tanggal_lahir <= 19)
echo ‘Anda Berzodiak <b>AQUARIUS</b>’;
else
echo ‘Anda Berzodiak <b>PISCES</b>’;
}else if($bulan_lahir == 3){
if($tanggal_lahir <= 20)
echo ‘Anda Berzodiak <b>PISCES</b>’;
else
echo ‘Anda Berzodiak <b>ARIES</b>’;
}else if($bulan_lahir == 4){
if($tanggal_lahir <= 19)
echo ‘Anda Berzodiak <b>ARIES</b>’;
else
echo ‘Anda Berzodiak <b>TAURUS</b>’;
}else if($bulan_lahir == 4){
if($tanggal_lahir <= 19)
echo ‘Anda Berzodiak <b>ARIES</b>’;
else
echo ‘Anda Berzodiak <b>TAURUS</b>’;
}else if($bulan_lahir == 5){
if($tanggal_lahir <= 20)
echo ‘Anda Berzodiak <b>TAURUS</b>’;
else
echo ‘Anda Berzodiak <b>GEMINI</b>’;
}else if($bulan_lahir == 6){
if($tanggal_lahir <= 21)
echo ‘Anda Berzodiak <b>GEMINI</b>’;
else
echo ‘Anda Berzodiak <b>CANCER</b>’;
}else if($bulan_lahir == 7){
if($tanggal_lahir <= 22)
echo ‘Anda Berzodiak <b>CANCER</b>’;
else
echo ‘Anda Berzodiak <b>LEO</b>’;
}else if($bulan_lahir == 8){
if($tanggal_lahir <= 23)
echo ‘Anda Berzodiak <b>LEO</b>’;
else
echo ‘Anda Berzodiak <b>VIRGO</b>’;
}else if($bulan_lahir == 9){
if($tanggal_lahir <= 22)
echo ‘Anda Berzodiak <b>VIRGO</b>’;
else
echo ‘Anda Berzodiak <b>LIBRA</b>’;
}else if($bulan_lahir == 10){
if($tanggal_lahir <= 23)
echo ‘Anda Berzodiak <b>LIBRA</b>’;
else
echo ‘Anda Berzodiak <b>SCORPIO</b>’;
}else if($bulan_lahir == 11){
if($tanggal_lahir <= 22)
echo ‘Anda Berzodiak <b>SCORPIO</b>’;
else
echo ‘Anda Berzodiak <b>SAGITARIUS</b>’;
}else if($bulan_lahir == 12){
if($tanggal_lahir <= 21)
echo ‘Anda Berzodiak <b>SAGITARIUS</b>’;
else
echo ‘Anda Berzodiak <b>CAPRICORN</b>’;
}else {
echo ‘Bulan yang anda masukkan salah’;
}
if($tanggal_lahir <= 20)
echo ‘Anda Berzodiak <b>CAPRICORN</b>’;
else
echo ‘Anda Berzodiak <b>AQUARIUS</b>’;
}else if($bulan_lahir == 2){
if($tanggal_lahir <= 19)
echo ‘Anda Berzodiak <b>AQUARIUS</b>’;
else
echo ‘Anda Berzodiak <b>PISCES</b>’;
}else if($bulan_lahir == 3){
if($tanggal_lahir <= 20)
echo ‘Anda Berzodiak <b>PISCES</b>’;
else
echo ‘Anda Berzodiak <b>ARIES</b>’;
}else if($bulan_lahir == 4){
if($tanggal_lahir <= 19)
echo ‘Anda Berzodiak <b>ARIES</b>’;
else
echo ‘Anda Berzodiak <b>TAURUS</b>’;
}else if($bulan_lahir == 4){
if($tanggal_lahir <= 19)
echo ‘Anda Berzodiak <b>ARIES</b>’;
else
echo ‘Anda Berzodiak <b>TAURUS</b>’;
}else if($bulan_lahir == 5){
if($tanggal_lahir <= 20)
echo ‘Anda Berzodiak <b>TAURUS</b>’;
else
echo ‘Anda Berzodiak <b>GEMINI</b>’;
}else if($bulan_lahir == 6){
if($tanggal_lahir <= 21)
echo ‘Anda Berzodiak <b>GEMINI</b>’;
else
echo ‘Anda Berzodiak <b>CANCER</b>’;
}else if($bulan_lahir == 7){
if($tanggal_lahir <= 22)
echo ‘Anda Berzodiak <b>CANCER</b>’;
else
echo ‘Anda Berzodiak <b>LEO</b>’;
}else if($bulan_lahir == 8){
if($tanggal_lahir <= 23)
echo ‘Anda Berzodiak <b>LEO</b>’;
else
echo ‘Anda Berzodiak <b>VIRGO</b>’;
}else if($bulan_lahir == 9){
if($tanggal_lahir <= 22)
echo ‘Anda Berzodiak <b>VIRGO</b>’;
else
echo ‘Anda Berzodiak <b>LIBRA</b>’;
}else if($bulan_lahir == 10){
if($tanggal_lahir <= 23)
echo ‘Anda Berzodiak <b>LIBRA</b>’;
else
echo ‘Anda Berzodiak <b>SCORPIO</b>’;
}else if($bulan_lahir == 11){
if($tanggal_lahir <= 22)
echo ‘Anda Berzodiak <b>SCORPIO</b>’;
else
echo ‘Anda Berzodiak <b>SAGITARIUS</b>’;
}else if($bulan_lahir == 12){
if($tanggal_lahir <= 21)
echo ‘Anda Berzodiak <b>SAGITARIUS</b>’;
else
echo ‘Anda Berzodiak <b>CAPRICORN</b>’;
}else {
echo ‘Bulan yang anda masukkan salah’;
}
?>
</body>
</html>
</html>
OUTPUT NYA :
swi-case-if
<!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”>
“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 3. Struktur Kontrol</tittle>
<meta http-equiv=”content-type” content=”text/html; charsct=utf-8″ />
<meta name=”generator” content=”Geany 0.20″ />
</head>
<tittle>Praktikum 3. Struktur Kontrol</tittle>
<meta http-equiv=”content-type” content=”text/html; charsct=utf-8″ />
<meta name=”generator” content=”Geany 0.20″ />
</head>
<body>
<?php
$tanggal_lahir = 16;
$bulan_lahir = 6;
switch ($bulan_lahir){
case 1:
if($tanggal_lahir <= 20)
echo ‘Anda Berzodiak <b>CAPRICON</b>’;
else
echo ‘Anda Berzodiak <b>AQUARIUS</b>’;
break;
case 2:
if($tanggal_lahir <= 19)
echo ‘Anda Berzodiak <b>AQUARIUS</b>’;
else
echo ‘Anda Berzodiak <b>PISCES</b>’;
break;
case 3:
if($tanggal_lahir <= 20)
echo ‘Anda Berzodiak <b>PISCES</b>’;
else
echo ‘Anda Berzodiak <b>ARIES</b>’;
break;
case 4:
if($tanggal_lahir <= 19)
echo ‘Anda Berzodiak <b>ARIES</b>’;
else
echo ‘Anda Berzodiak <b>TAURUS</b>’;
break;
case 5:
if($tanggal_lahir <= 20)
echo ‘Anda Berzodiak <b>TAURUS</b>’;
else
echo ‘Anda Berzodiak <b>GEMINI</b>’;
break;
case 6:
if($tanggal_lahir <= 21)
echo ‘Anda Berzodiak <b>GEMINI</b>’;
else
echo ‘Anda Berzodiak <b>CANCER</b>’;
break;
case 7:
if($tanggal_lahir <= 22)
echo ‘Anda Berzodiak <b>CANCER</b>’;
else
echo ‘Anda Berzodiak <b>LEO</b>’;
break;
case 8:
if($tanggal_lahir <= 23)
echo ‘Anda Berzodiak <b>LEO</b>’;
else
echo ‘Anda Berzodiak <b>VIRGO</b>’;
break;
case 9:
if($tanggal_lahir <= 22)
echo ‘Anda Berzodiak <b>VIRGO</b>’;
else
echo ‘Anda Berzodiak <b>LIBRA</b>’;
break;
case 10:
if($tanggal_lahir <= 23)
echo ‘Anda Berzodiak <b>LIBRA</b>’;
else
echo ‘Anda Berzodiak <b>SCORPIO</b>’;
break;
case 11:
if($tanggal_lahir <= 22)
echo ‘Anda Berzodiak <b>SCORPIO</b>’;
else
echo ‘Anda Berzodiak <b>SAGITARIUS</b>’;
break;
case 12:
if($tanggal_lahir <= 21)
echo ‘Anda Berzodiak <b>SAGITARIUS</b>’;
else
echo ‘Anda Berzodiak <b>CAPRICON</b>’;
break;
default:
echo ‘Zodiak Tidak Terdaftar’;
break;
}
?>
<?php
$tanggal_lahir = 16;
$bulan_lahir = 6;
switch ($bulan_lahir){
case 1:
if($tanggal_lahir <= 20)
echo ‘Anda Berzodiak <b>CAPRICON</b>’;
else
echo ‘Anda Berzodiak <b>AQUARIUS</b>’;
break;
case 2:
if($tanggal_lahir <= 19)
echo ‘Anda Berzodiak <b>AQUARIUS</b>’;
else
echo ‘Anda Berzodiak <b>PISCES</b>’;
break;
case 3:
if($tanggal_lahir <= 20)
echo ‘Anda Berzodiak <b>PISCES</b>’;
else
echo ‘Anda Berzodiak <b>ARIES</b>’;
break;
case 4:
if($tanggal_lahir <= 19)
echo ‘Anda Berzodiak <b>ARIES</b>’;
else
echo ‘Anda Berzodiak <b>TAURUS</b>’;
break;
case 5:
if($tanggal_lahir <= 20)
echo ‘Anda Berzodiak <b>TAURUS</b>’;
else
echo ‘Anda Berzodiak <b>GEMINI</b>’;
break;
case 6:
if($tanggal_lahir <= 21)
echo ‘Anda Berzodiak <b>GEMINI</b>’;
else
echo ‘Anda Berzodiak <b>CANCER</b>’;
break;
case 7:
if($tanggal_lahir <= 22)
echo ‘Anda Berzodiak <b>CANCER</b>’;
else
echo ‘Anda Berzodiak <b>LEO</b>’;
break;
case 8:
if($tanggal_lahir <= 23)
echo ‘Anda Berzodiak <b>LEO</b>’;
else
echo ‘Anda Berzodiak <b>VIRGO</b>’;
break;
case 9:
if($tanggal_lahir <= 22)
echo ‘Anda Berzodiak <b>VIRGO</b>’;
else
echo ‘Anda Berzodiak <b>LIBRA</b>’;
break;
case 10:
if($tanggal_lahir <= 23)
echo ‘Anda Berzodiak <b>LIBRA</b>’;
else
echo ‘Anda Berzodiak <b>SCORPIO</b>’;
break;
case 11:
if($tanggal_lahir <= 22)
echo ‘Anda Berzodiak <b>SCORPIO</b>’;
else
echo ‘Anda Berzodiak <b>SAGITARIUS</b>’;
break;
case 12:
if($tanggal_lahir <= 21)
echo ‘Anda Berzodiak <b>SAGITARIUS</b>’;
else
echo ‘Anda Berzodiak <b>CAPRICON</b>’;
break;
default:
echo ‘Zodiak Tidak Terdaftar’;
break;
}
?>
</body>
</html>
output nya :
struktur3-5
<!DOCTYPE html PUBLIC “//W3C//DTD XHTML 1.0 Strict//EN”
“http://www.w3.org/TR/xhtml1/DTD/xhtml1strict.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml” xml:lang=”en” lang=”en”>
“http://www.w3.org/TR/xhtml1/DTD/xhtml1strict.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml” xml:lang=”en” lang=”en”>
<head>
<title>Praktikum 3. Struktur Kontrol</title>
<meta httpequiv=”contenttype”content=”text/html;charset=utf8″/>
<meta name=”generator” content=”Geany 0.20″ />
</head>
<title>Praktikum 3. Struktur Kontrol</title>
<meta httpequiv=”contenttype”content=”text/html;charset=utf8″/>
<meta name=”generator” content=”Geany 0.20″ />
</head>
<body>
<?php
$hari_ini = ‘Rabu’;
switch ($hari_ini){
case ‘Senin’;
echo ‘Hari Senin’;
break;
case ‘Selasa’;
echo ‘Hari Selasa’;
break;
case ‘Rabu’;
echo ‘Hari Rabu’;
break;
case ‘Kamis’;
echo ‘Kamis’;
break;
case ‘Jumat’;
echo ‘Hari Jumat’;
break;
case ‘Sabtu’;
echo ‘Hari Sabtu’;
break;
case ‘Minggu’;
echo ‘Hari Minggu’;
break;
default:
echo ‘Hari tidak Terdaftar’;
break;
}
?>
<?php
$hari_ini = ‘Rabu’;
switch ($hari_ini){
case ‘Senin’;
echo ‘Hari Senin’;
break;
case ‘Selasa’;
echo ‘Hari Selasa’;
break;
case ‘Rabu’;
echo ‘Hari Rabu’;
break;
case ‘Kamis’;
echo ‘Kamis’;
break;
case ‘Jumat’;
echo ‘Hari Jumat’;
break;
case ‘Sabtu’;
echo ‘Hari Sabtu’;
break;
case ‘Minggu’;
echo ‘Hari Minggu’;
break;
default:
echo ‘Hari tidak Terdaftar’;
break;
}
?>
</body>
</html>
</html>
Output nya :
praktikum 3.3 penggunaan if diganti dengan penggunaan switch-case
<!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”>
“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 3. Struktur Kontrol</tittle>
<meta http-equiv=”content-type” content=”text/html; charsct=utf-8″ />
<meta name=”generator” content=”Geany 0.20″ />
</head>
<tittle>Praktikum 3. Struktur Kontrol</tittle>
<meta http-equiv=”content-type” content=”text/html; charsct=utf-8″ />
<meta name=”generator” content=”Geany 0.20″ />
</head>
<body>
<?php
$bulan_lahir = 6;
switch ($bulan_lahir){
case 1:
echo ‘Anda lahir di bulan Januari’;
break;
case 2:
echo ‘Anda lahir di bulan Februari ‘;
break;
case 3:
echo ‘Anda lahir di bulan Maret’;
break;
case 4:
echo ‘Anda lahir di bulan April’;
break;
case 5:
echo ‘Anda lahir di bulan Mei’;
break;
case 6:
echo ‘Anda lahir di bulan Juni’;
break;
case 7:
echo ‘Anda lahir di bulan Juli’;
break;
case 8:
echo ‘Anda lahir di bulan Agustus’;
break;
case 9:
echo ‘Anda lahir di bulan September’;
break;
case 10:
echo ‘Anda lahir di bulan Oktober’;
break;
case 11:
echo ‘Anda lahir di bulan November’;
break;
case 12:
echo ‘Anda lahir di bulan Desember’;
break;
default:
echo ‘bulan Tidak Terdaftar’;
break;
}
?>
</body>
</html>
<?php
$bulan_lahir = 6;
switch ($bulan_lahir){
case 1:
echo ‘Anda lahir di bulan Januari’;
break;
case 2:
echo ‘Anda lahir di bulan Februari ‘;
break;
case 3:
echo ‘Anda lahir di bulan Maret’;
break;
case 4:
echo ‘Anda lahir di bulan April’;
break;
case 5:
echo ‘Anda lahir di bulan Mei’;
break;
case 6:
echo ‘Anda lahir di bulan Juni’;
break;
case 7:
echo ‘Anda lahir di bulan Juli’;
break;
case 8:
echo ‘Anda lahir di bulan Agustus’;
break;
case 9:
echo ‘Anda lahir di bulan September’;
break;
case 10:
echo ‘Anda lahir di bulan Oktober’;
break;
case 11:
echo ‘Anda lahir di bulan November’;
break;
case 12:
echo ‘Anda lahir di bulan Desember’;
break;
default:
echo ‘bulan Tidak Terdaftar’;
break;
}
?>
</body>
</html>
OUTPUT :
Praktikum 3.4 Ubah menjadi switch-case dan if yang di dalam tetap tanpa mengganti apapun.
<!DOCTYPE html PUBLIC “//W3C//DTD XHTML 1.0 Strict//EN”
“http://www.w3.org/TR/xhtml1/DTD/xhtml1strict.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml” xml:lang=”en” lang=”en”>
“http://www.w3.org/TR/xhtml1/DTD/xhtml1strict.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml” xml:lang=”en” lang=”en”>
<head>
<tittle>Praktikum 3. Struktur Kontrol</tittle>
<meta http-equiv=”content-type” content=”text/html; charsct=utf-8″ />
<meta name=”generator” content=”Geany 0.20″ />
</head>
<tittle>Praktikum 3. Struktur Kontrol</tittle>
<meta http-equiv=”content-type” content=”text/html; charsct=utf-8″ />
<meta name=”generator” content=”Geany 0.20″ />
</head>
<body>
<?php
$tanggal_lahir = 16;
$bulan_lahir = 6;
<?php
$tanggal_lahir = 16;
$bulan_lahir = 6;
if($bulan_lahir == 1){
if($tanggal_lahir <= 20)
echo ‘Anda Berzodiak <b>CAPRICORN</b>’;
else
echo ‘Anda Berzodiak <b>AQUARIUS</b>’;
}else if($bulan_lahir == 2){
if($tanggal_lahir <= 19)
echo ‘Anda Berzodiak <b>AQUARIUS</b>’;
else
echo ‘Anda Berzodiak <b>PISCES</b>’;
}else if($bulan_lahir == 3){
if($tanggal_lahir <= 20)
echo ‘Anda Berzodiak <b>PISCES</b>’;
else
echo ‘Anda Berzodiak <b>ARIES</b>’;
}else if($bulan_lahir == 4){
if($tanggal_lahir <= 19)
echo ‘Anda Berzodiak <b>ARIES</b>’;
else
echo ‘Anda Berzodiak <b>TAURUS</b>’;
}else if($bulan_lahir == 4){
if($tanggal_lahir <= 19)
echo ‘Anda Berzodiak <b>ARIES</b>’;
else
echo ‘Anda Berzodiak <b>TAURUS</b>’;
}else if($bulan_lahir == 5){
if($tanggal_lahir <= 20)
echo ‘Anda Berzodiak <b>TAURUS</b>’;
else
echo ‘Anda Berzodiak <b>GEMINI</b>’;
}else if($bulan_lahir == 6){
if($tanggal_lahir <= 21)
echo ‘Anda Berzodiak <b>GEMINI</b>’;
else
echo ‘Anda Berzodiak <b>CANCER</b>’;
}else if($bulan_lahir == 7){
if($tanggal_lahir <= 22)
echo ‘Anda Berzodiak <b>CANCER</b>’;
else
echo ‘Anda Berzodiak <b>LEO</b>’;
}else if($bulan_lahir == 8){
if($tanggal_lahir <= 23)
echo ‘Anda Berzodiak <b>LEO</b>’;
else
echo ‘Anda Berzodiak <b>VIRGO</b>’;
}else if($bulan_lahir == 9){
if($tanggal_lahir <= 22)
echo ‘Anda Berzodiak <b>VIRGO</b>’;
else
echo ‘Anda Berzodiak <b>LIBRA</b>’;
}else if($bulan_lahir == 10){
if($tanggal_lahir <= 23)
echo ‘Anda Berzodiak <b>LIBRA</b>’;
else
echo ‘Anda Berzodiak <b>SCORPIO</b>’;
}else if($bulan_lahir == 11){
if($tanggal_lahir <= 22)
echo ‘Anda Berzodiak <b>SCORPIO</b>’;
else
echo ‘Anda Berzodiak <b>SAGITARIUS</b>’;
}else if($bulan_lahir == 12){
if($tanggal_lahir <= 21)
echo ‘Anda Berzodiak <b>SAGITARIUS</b>’;
else
echo ‘Anda Berzodiak <b>CAPRICORN</b>’;
}else {
echo ‘Bulan yang anda masukkan salah’;
}
if($tanggal_lahir <= 20)
echo ‘Anda Berzodiak <b>CAPRICORN</b>’;
else
echo ‘Anda Berzodiak <b>AQUARIUS</b>’;
}else if($bulan_lahir == 2){
if($tanggal_lahir <= 19)
echo ‘Anda Berzodiak <b>AQUARIUS</b>’;
else
echo ‘Anda Berzodiak <b>PISCES</b>’;
}else if($bulan_lahir == 3){
if($tanggal_lahir <= 20)
echo ‘Anda Berzodiak <b>PISCES</b>’;
else
echo ‘Anda Berzodiak <b>ARIES</b>’;
}else if($bulan_lahir == 4){
if($tanggal_lahir <= 19)
echo ‘Anda Berzodiak <b>ARIES</b>’;
else
echo ‘Anda Berzodiak <b>TAURUS</b>’;
}else if($bulan_lahir == 4){
if($tanggal_lahir <= 19)
echo ‘Anda Berzodiak <b>ARIES</b>’;
else
echo ‘Anda Berzodiak <b>TAURUS</b>’;
}else if($bulan_lahir == 5){
if($tanggal_lahir <= 20)
echo ‘Anda Berzodiak <b>TAURUS</b>’;
else
echo ‘Anda Berzodiak <b>GEMINI</b>’;
}else if($bulan_lahir == 6){
if($tanggal_lahir <= 21)
echo ‘Anda Berzodiak <b>GEMINI</b>’;
else
echo ‘Anda Berzodiak <b>CANCER</b>’;
}else if($bulan_lahir == 7){
if($tanggal_lahir <= 22)
echo ‘Anda Berzodiak <b>CANCER</b>’;
else
echo ‘Anda Berzodiak <b>LEO</b>’;
}else if($bulan_lahir == 8){
if($tanggal_lahir <= 23)
echo ‘Anda Berzodiak <b>LEO</b>’;
else
echo ‘Anda Berzodiak <b>VIRGO</b>’;
}else if($bulan_lahir == 9){
if($tanggal_lahir <= 22)
echo ‘Anda Berzodiak <b>VIRGO</b>’;
else
echo ‘Anda Berzodiak <b>LIBRA</b>’;
}else if($bulan_lahir == 10){
if($tanggal_lahir <= 23)
echo ‘Anda Berzodiak <b>LIBRA</b>’;
else
echo ‘Anda Berzodiak <b>SCORPIO</b>’;
}else if($bulan_lahir == 11){
if($tanggal_lahir <= 22)
echo ‘Anda Berzodiak <b>SCORPIO</b>’;
else
echo ‘Anda Berzodiak <b>SAGITARIUS</b>’;
}else if($bulan_lahir == 12){
if($tanggal_lahir <= 21)
echo ‘Anda Berzodiak <b>SAGITARIUS</b>’;
else
echo ‘Anda Berzodiak <b>CAPRICORN</b>’;
}else {
echo ‘Bulan yang anda masukkan salah’;
}
?>
</body>
</html>
</html>
output:
0 komentar: