简体   繁体   中英

php - Right Angle Triangle

I am new in PHP programming.Can anyone explain this code step by step?

for($i=1; $i<=5; $i++){
 for($j=1; $j<=$i; $j++){
    echo "*";
 }
 echo"<br>";
}

The outer loop ($i) goes from 1 to 5. You can think of this as the rows of output in this case.

Within each row, the inner loop ($j) prints out a quantity of $i asterisks. So in row 1, it outputs * , row 2, ** , and so on.

Before moving on to the next row, it prints out a line break. So the final output will be something like:

*
**
***
****
*****

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM