Using a repeat structure, print the following on the screen:
*
**
***
****
*****
******
*******
Using a repeat structure, print the following on the screen:
*
**
***
****
*****
******
*******
I understand that since this is an exercise, @DiegoF's answer is the correct one for the question.
Just for reference, there is a version using str_repeat
, more suitable if it is for an actual application:
for( $i = 0; $i < 7; ++$i ) echo str_repeat( '*', $i ) . "\n";
See working at IDEONE .
If it is to be used in HTML, change "\n"
to '<br>'
, or even "<br>\n"
(and duplicate if you want the lines blank).
You can use 2 loops, the outer one controls the row change and another prints the respective amount of *
of that row.
See:
for($i = 0; $i < 7; $i++){
for($j = 0; $j <= $i; $j++){
echo "*";
}
echo "\n\n";
}
See working at IDEONE . As you did not make it clear if this line spacing was part of it, I added one more break, so the output stays:
*
**
***
****
*****
******
*******