For Loop. Cant get it to work

I am very new to PHP and I just cant get this to work correctly. I have tried serval ways and looked through this site for guidance. I am at a loss and I am hoping some one can help me.
-I wrote serval lines of code (for loops) which print a series of number. The problem is I want each loop to display on it own line.

<?php

for ($i=4; $i <= 10; $i++) {

 echo "$i ";

}

for ($x=6; $x > 0; $x--) {

  echo "$x ";

 

}

for ($y=2; $y <= 16; $y+=2) {

  echo "$y ";

}  

for ($num=19; $num >= 5; $num-=2) {

  echo "$num ";

}

?>

I have tried adding a break; after the echo statement but it just stops the loop at the first value.

Thanks

How? That is all you need to do on each echo.

echo "$i<br>";

So when I do that for example on the first for loop: for ($i=4; $i <= 10; $i++) {
print ā€œ$i
ā€;
}
It will list each number on its own line. I want all the numbers for this loop on one line.
then the next series of numbers, for the next loop on a new line.

Then put the break between the loops.

Can you so an example, please. I did it like this for ($i=4; $i <= 10; $i++) {
print ā€œ$iā€;
break;
} //This is wrong
also tried for ($i=4; $i <= 10; $i++) {
print ā€œ$iā€;
}
break;

for ($x=6; $x > 0; $xā€“) // which is also wrong.
Thank you so much for all your help.

Not that kind of break. An html break like I showed you.

1 Like

OMG! I finally got it! Thank You ssooooo much.

1 Like
Sponsor our Newsletter | Privacy Policy | Terms of Service