helpmepleasplease5 Posted March 13, 2013 Share Posted March 13, 2013 I need to calculate the sum of the integers from 1 to 100 using while, for, and do-while. I have no idea how to start or what to do. Thank you! Quote Link to comment https://forums.phpfreaks.com/topic/275620-calculate-the-sum-of-the-integers-from-1-to-100-using-while-for-and-do-while/ Share on other sites More sharing options...
AyKay47 Posted March 13, 2013 Share Posted March 13, 2013 (edited) $n = 0; $sum = 0; while($n<=100) { $sum += $n; $n++; } Edited March 13, 2013 by AyKay47 Quote Link to comment https://forums.phpfreaks.com/topic/275620-calculate-the-sum-of-the-integers-from-1-to-100-using-while-for-and-do-while/#findComment-1418445 Share on other sites More sharing options...
helpmepleasplease5 Posted March 13, 2013 Author Share Posted March 13, 2013 Hi! So sorry! Thank you for your help! I am just learning PHP my professor doesn't speak English. I'm struggling! Quote Link to comment https://forums.phpfreaks.com/topic/275620-calculate-the-sum-of-the-integers-from-1-to-100-using-while-for-and-do-while/#findComment-1418447 Share on other sites More sharing options...
Barand Posted March 13, 2013 Share Posted March 13, 2013 or for ($i=1, $sum=0; $i<=100; $sum += $i++); Quote Link to comment https://forums.phpfreaks.com/topic/275620-calculate-the-sum-of-the-integers-from-1-to-100-using-while-for-and-do-while/#findComment-1418470 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.