Looping 3: Blank Diamond

Soal yang ketiga ini mirip dengan soal yang kedua.

Hasil tampilan yang diinginkan adalah seperti ini:

loopong: blank diamond

Dan ini kode sumbernya:

<?php
$star = '*';
$line = '-';
$space = ' ';

for ($j = 8; $j >= 2; $j--) {
    for ($k = 2; $k <= $j; $k++) {
        echo $line;
    }
    echo $star;
    for ($l = $j; $l <= 7; $l++) {
        echo $space;
    }
    for ($l = $j; $l <= 7; $l++) {
        echo $space;
    }
    echo $star;
    for ($k = 2; $k <= $j; $k++) {
        echo $line;
    }
    echo "n";
}
for ($j = 8; $j >= 2; $j--) {
    for ($l = $j; $l <= 8; $l++) {
        echo $line;
    }
    echo $star;
    for ($k = 3; $k <= $j; $k++) {
        echo $space;
    }
    for ($k = 3; $k <= $j; $k++) {
        echo $space;
    }
    echo $star;
    for ($l = $j; $l <= 8; $l++) {
        echo $line;
    }
    echo "n";
}
?>

Yak, inilah seri terakhir yang menutup trilogi looping ini.

Oh ya, Happy Birthday, Len! :mrgreen:

Published by Eric Gunawan

Happiness Engineer. WordPress Ambassador. Remote Worker. Soccer News Follower. Movie Lover. Proud Father. Lucky Husband.

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 )

Google photo

You are commenting using your Google 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 )

Connecting to %s

%d bloggers like this: