This forum is now read-only. Please use our new forums at discuss.codecademy.com.

For Loops in PHP Forum

View Course » View Exercise

679 points
B812ae98ee0c7cd63de3d0f49fd4c9a7?s=140&d=retro
Submitted by
LordChico
about 3 years ago

Spacing with echo in a for loop...?

my code looks like this:
<?php
for ($i = 0; $i < 101; $i = $i + 10) {
echo $i;
};
?>
and it turns up as 0102030405060708090100
and trying to figure out:

  1. how do I space it?
  2. how do I make it on separate lines?

Thnx in advance.


2 votes

permalink

    <?php
    // space them
        for ($i = 0; $i < 101; $i = $i + 10) {
            echo $i . ' ';
        }
    ?>

365 points
543fc82f631fe988640020d7_382532424
Submitted by
Tobias Páez
about 3 years ago


0 votes

permalink

    <?php
    // separate lines
        for ($i = 0; $i < 101; $i = $i + 10) {
            echo $i . '<br/ > ';
        }
    ?>

365 points
543fc82f631fe988640020d7_382532424
Submitted by
Tobias Páez
about 3 years ago