Help Convert This WHILE Loop Into A FOR Loop - Programming - Nairaland
Nairaland Forum › Science/Technology › Programming › Help Convert This WHILE Loop Into A FOR Loop (2180 Views)
| Help Convert This WHILE Loop Into A FOR Loop by Talk2bryant(op): 8:51pm On Jul 11, 2015 |
Int i= 1; Int sum = 0; while (sum < 10) { sum = sum + i; i++; } |
| Re: Help Convert This WHILE Loop Into A FOR Loop by omoelu1(m): 10:43pm On Jul 11, 2015 |
public class ReWrite{Goodluck!!! |
| Re: Help Convert This WHILE Loop Into A FOR Loop by hisabimbola(m): 10:51pm On Jul 11, 2015 |
This question sounds funny, guess that's why you got no response, but either ways
Wrote it in JS, but you should be able to convert it |
| Re: Help Convert This WHILE Loop Into A FOR Loop by Nobody: 11:26pm On Jul 11, 2015 |
My own simple answer(after girraffing some of the codes above) is: In Java: Int sum=0;In JavaScript: sum=0;In PHP: $sum=0;I have already used my eyes to debug it - it will work. . . . |
| Re: Help Convert This WHILE Loop Into A FOR Loop by fattbabakay(m): 9:25am On Jul 12, 2015 |
dhtml18:Guruuuuuuuu!!! |
| Re: Help Convert This WHILE Loop Into A FOR Loop by Damey2011(m): 9:14am On Jul 13, 2015 |
dhtml18:The Increment is applicable to the integer i.. so the for line is for(sum = 0; sum < 10 ; sum ++){What I see about the code is just printing sum from 0-9.. but the essence of the int = 1 is to make is start from 1- 10 instead cos the computer is programmed to start counting from 0 for a reason I dont know |
| Re: Help Convert This WHILE Loop Into A FOR Loop by eDoc: 10:41am On Jul 13, 2015 |
if i understand your code well,this is in python. i had to study other code above, As i is incrementing from 1 to whatever,sum is adding it's self to the present state of i.
|
Javascript - For Loop • Help With Python Program (simple While Loop) • Programming Challenge: Convert String to Json with a Loop • 2 • 3 • 4
I'll Help With Any Ms Excel Issues Here • Coldfusion Vs Php Code Battle • Young Programmers in Abuja