+ 3

For loops and while loops.

What's the difference between the two loops? Or

27th Dec 2016, 3:34 PM
Bob
5 odpowiedzi
+ 4
Got it! Apparently for loops are easier to write.
27th Dec 2016, 3:40 PM
Bob
+ 2
For loops and while loops are the same. It's just that some people find for loops are more descriptive.
28th Dec 2016, 5:35 PM
iiRosie1
iiRosie1 - avatar
+ 1
for loops are easier to loop, it can loop to equal the length of the array or number for example; var newarr=["one "," two" ]; var num = 5; for (var i=0; i <newarr.length){ alert (i ); } for (var i=0; i <num){ alert (i ); } the first one will loop two times since the newarr only have two items. the second one will loop 5 times as long as i is less than 5. Remember that in looping 0 = 1, unless you set your counter to equal 1. Meanwhile, While loop will always loop as long as the statement of executed value is true. It is used when you don't really know how many times it will loop. I can agree that for and while are the same, it all depends on the conditions. var i =0; var num =5; while (i < num){ alert (i); i++ }
27th Dec 2016, 8:02 PM
Francis Bolaji
Francis Bolaji - avatar
+ 1
For loops and while loops are the same, it's just preference matters. :)
28th Dec 2016, 9:36 PM
Cherry
Cherry - avatar
0
please guys it is good to clear this for loops and while loop.. they both might look the same but in reality the are slightly different. please check this ref. http://stackoverflow.com/questions/18211806/difference-between-a-for-loop-and-a-while-loop-using-an-iterator
28th Dec 2016, 10:56 PM
Francis Bolaji
Francis Bolaji - avatar