Hi guys I need to make a diamond like this for my lecturer,using nested for statements. I am having troubles. Can you guys give me any tips? ty.

Recommended Answers

I'll give you a few pointers, but you don't need to nest anything.

rows = 9
increment/decrement amount = 2
symbol = *
(textalign = center - for layout)

With this info you can create any size of diamond, as long as the rows = odd number. Once you hit …

Jump to Post

All 3 Replies

Member Avatar

I'll give you a few pointers, but you don't need to nest anything.

rows = 9
increment/decrement amount = 2
symbol = *
(textalign = center - for layout)

With this info you can create any size of diamond, as long as the rows = odd number. Once you hit the middle value (5 in this case), you change the increment by 2 to decrement by 2. There are many, many ways to do this though.

 <?PHP
    $b = 1;
    for ($a=1; $a<=5; $a++)
    {
    echo str_repeat('*', $b);
    $b++;


    echo "<br>";
    }
    ?>
Member Avatar

^^ that won't produce a diamond - only a triangle. And ..

Can you guys give me any tips

So let's give him tips, not putative solutions.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.