View Full Version : Resolved Changing For loop to While loop

11-12-2010, 09:55 PM

I am doing some studying and we was to create a small loop using either the for loop, while loop or do while loop. I chose to do the for loop because it was easier to understand, but I want to know how to do the same using the while loop. Here is the for loop I have, but I cant figure out how to change to while loop.

for (var i = 0; i < 5; ++i)
for (var j = i; j < 5; ++j)
document.write(j + "");
document.write("<br />");

output is equal to:

How do you make the same using a while loop?

Old Pedant
11-12-2010, 09:59 PM
LOL! Took you a whole 2 minutes to solve it?

11-12-2010, 10:26 PM
I want to know how to do the same using the while loop

Last edited by zairne86; 11-12-2010 at 10:57 PM.. Reason: Solved

An unwritten Forum's rule, all over, says that you should also post the solution, even if you found it by yourself. As you had this problem today, another one might have it tomorrow, and it will be nice if you could help him in advance, wouldn't it?