crodbos Posted September 29, 2010 Share Posted September 29, 2010 1- Write a PHP program that goes through all integers between 1 and 100 (excluding 1 and 0) and displays each even number on a separate line. 2- Re-write the program in question 1 but this time use a function to go through the numbers and display them. I have the following. How can I do the other one? :'( <?php for ($i = 2; $i <= 100; $i++) { if ($i % 2 == 0){ print $i . " <Br> "; } } ?> Link to comment https://forums.phpfreaks.com/topic/214686-how-can-i-make-too-different-php-programs-that-capture-the-following/ Share on other sites More sharing options...
PFMaBiSmAd Posted September 29, 2010 Share Posted September 29, 2010 You do realize that programming help forums don't do homework for you? Link to comment https://forums.phpfreaks.com/topic/214686-how-can-i-make-too-different-php-programs-that-capture-the-following/#findComment-1117006 Share on other sites More sharing options...
coupe-r Posted September 29, 2010 Share Posted September 29, 2010 Very simple. function homework() { for ($i = 2; $i <= 100; $i++) { if ($i % 2 == 0) { echo $i.'<br />'; } } } homework(); Link to comment https://forums.phpfreaks.com/topic/214686-how-can-i-make-too-different-php-programs-that-capture-the-following/#findComment-1117008 Share on other sites More sharing options...
crodbos Posted September 29, 2010 Author Share Posted September 29, 2010 Than you! That was great help. I'm learning it from a book, but it's confusing...it's not homework. Link to comment https://forums.phpfreaks.com/topic/214686-how-can-i-make-too-different-php-programs-that-capture-the-following/#findComment-1117023 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.