php for loop

hi I was trying to loop for loop 5 times to echo 'hi all' 5 times. But i see output getting echoed only 1 time.

my code looks like

<?php

for($num=1; $num<=5; $num++);
{
echo "hi all"."<br/>";
}

?>

i was not sure what is the issue. Please advise on how to see echoed message 5 times

Open in new window

LVL 7
gudii9Asked:
Who is Participating?
 
käµfm³d 👽Connect With a Mentor Commented:
You have  a trailing semi-colon on line 3. Remove that and it should work fine.
0
 
Ray PaseurConnect With a Mentor Commented:
Some good learning resources for programmers new to PHP...
http://php.net/tut.php (read every page that is linked)
http://www.sitepoint.com/books/phpmysql4/ (worth every penny, and the time it takes to work through the exercises in the book)

Please make a Google search for "Zend Coding Standards" and learn why professional programmers indent their control structures.  Learn why we deliberately omit the close-php tag.  Learn why we use error_reporting(E_ALL).

Most importantly, please post back if you have any questions!  All the best, ~Ray
<?php
error_reporting(E_ALL);

for($num=1; $num<=5; $num++)
{
    echo "hi all THIS IS $num <br/>" . PHP_EOL;
}

Open in new window

0
 
Mohamed AbowardaConnect With a Mentor Software EngineerCommented:
When you use "for", "if" or "while" statement you shouldn't use semi-colon at the end, the following code should work for you:

<?php

for($num=1; $num<=5; $num++)
{
echo "hi all"."<br/>";
}

?>

Open in new window

0
 
käµfm³d 👽Commented:
...and the award for not reading the prior comments before posting goes to...
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.