Dark-Hawk Posted May 18, 2009 Share Posted May 18, 2009 Trying to come up with a way to print out every 5th number, so 5, 10, 15, 20, etc. I'm presuming a for loop is needed here but I'm unsure how to go about doing it. Thanks in advance guys. Link to comment https://forums.phpfreaks.com/topic/158609-solved-one-more-for-loop-question-multiples-of-5/ Share on other sites More sharing options...
Ken2k7 Posted May 18, 2009 Share Posted May 18, 2009 $limit = 60; $count = 0; $scale = 5; while ($count <= $limit) { echo $count; $count += $scale; } You can use a for loop, but I like while loops. for ($count = 0; $count <= 60; $count += 5) { echo $count; } Link to comment https://forums.phpfreaks.com/topic/158609-solved-one-more-for-loop-question-multiples-of-5/#findComment-836505 Share on other sites More sharing options...
kickstart Posted May 18, 2009 Share Posted May 18, 2009 Hi Or with a for loop for ($iCnt = 5; $iCnt <= 60; $iCnt += 5) { echo "$iCnt<br />"; } That would give you every number divisable 5 between 5 and 60. All the best Keith Link to comment https://forums.phpfreaks.com/topic/158609-solved-one-more-for-loop-question-multiples-of-5/#findComment-836508 Share on other sites More sharing options...
Dark-Hawk Posted May 18, 2009 Author Share Posted May 18, 2009 Great, thanks for the help guys Link to comment https://forums.phpfreaks.com/topic/158609-solved-one-more-for-loop-question-multiples-of-5/#findComment-836509 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.