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! 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 $n = 0; $sum = 0; while($n<=100) { $sum += $n; $n++; } 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! 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++); 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
Archived
This topic is now archived and is closed to further replies.