• Laporan praktikum 4

    Praktikum 4.1 Percabangan While <!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>  
     
    • Coding di atas diatas sehinnga memiliki output segitiga bawah,maka codenya adalah sebagai berikut:
    <!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 = 0 ;
            $i = 10;
            while ($i >= $tinggi){
                $j = 0;      
                while($j <=$i){
                    echo "*";
                    $j++;
                }
            echo "<br>";
            $i--;  
            }
        ?>
    </body>
    </html>   
     
    Praktikum 4.2 Perulangan Do...While
    <!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>
    • Ketikan kode berikut dan simpan 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>

    •      Modifikasi code di atas untuk menampilkan 100 baris tulisan,yang mana apabila itu baris ketiga dan kelipatannya akan bertuliskan "foo" dan jika baris kelima dan kelipatannya akan bertuliskan "bar" serta tiap baris ke 15 dan kelipatannya akan bertuliskan "foobar" selain ketentuan ini tulisan yang akan mucul adalah "ini baris ke x."
          maka code nya sebagai berikut :

     <!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 = 1;
                while ($x < 100){
                    if ($x % 15 == 0 ){
                        echo "foobar";
                    }else if($x % 5 == 0){
                        echo "bar"; 
                    }else if($x % 3 == 0){
                        echo "foo";
                    }else{
                        echo "ini baris ke-$x";
                    }
                    echo "<br>";
                    $x++;
                }
            ?>
    </body>
    </html>


     
    Praktikum 4.3 Perulangan for

    Gunakan perulangan for unutuk menggantikan code while pada praktikum 4.1 sehingga mendapatkan gambar  segitiga yang sama seperti pada gambar 4.1 & 4.2

    Struktur 1 for (segitiga atas)

    <!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>
     
    Struktur 2 for  (segitiga bawah)

    <!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><br>
        <meta http-equiv="content-type" content="text/html; charsct=utf-8" />
        <meta name="generator" content="Geany 0.20" />
    </head>
    <body>
        <?php
            $tinggi = 0;
            $i = 10;
            for ($i = 10 ; $i >= $tinggi ; $i--){
                for ($j = 0 ; $j < $i ; $j++ ){
                    echo "*";
                }
                    echo "<br>";
            }
        ?>
    </body>
    </html>

0 komentar:

Posting Komentar