+ 2

What is the difference between a for loop and a while loop? (Which is the best to use?)

9th Jan 2017, 7:27 PM
Sakul
10 Answers
+ 4
basically you can make a for loop using while loop and vice versa for loop is build more for running over array or to do a task n times while while is batter to run till something happened in the loop but as I said before you can use them both for every thing
9th Jan 2017, 7:58 PM
Manny Kroizer
Manny Kroizer - avatar
+ 3
there is not much difference in for or while loop,the difference lies in how we wanna use them!! for loop is great for beginners to get hold of looping and while is great if you are trying to build a complex code that simply LOOKS easy !! #SiD
9th Jan 2017, 7:45 PM
Siddharth Naithani
Siddharth Naithani - avatar
+ 2
there is no markable major difference,
10th Jan 2017, 5:53 PM
Nawaj Shareef
Nawaj Shareef - avatar
+ 1
Generally, I see a 'for' loop used with a counter/index and a 'while' loop when evaluating some arbitrary condition. Though, as pointed out, either can be used.
9th Jan 2017, 11:59 PM
Nathan
Nathan - avatar
+ 1
for is usually used for a sequence or a collection of iterates, a finit amount of elements and while for satisfying a certain condition. keep that in mind and you won't go wrong.
10th Jan 2017, 8:15 PM
dario
dario - avatar
0
the same functionalty that repeat piece of code but different at for: ----- for(you initialize start point and, condition that end loop when its true,and the step between for each iteration) while: ----- you can use it when you don't know the number of ireration start value if you Have it while(condition to end loop) { your code and you step if you have }
11th Jan 2017, 12:00 AM
Sarah Ramadan
Sarah Ramadan - avatar
0
There is a great difference between for loop and while loop. For loop is used to check certain conditions. Like, maybe, whether the condition is true or false. Whereas, While loop is used to check certain condition true. But, the loop is executed continuously and automatically until it is true. The instant it becomes false, it gets terminated.
11th Jan 2017, 4:03 AM
Balwinder Kumar
Balwinder Kumar - avatar
0
for loop is best option
11th Jan 2017, 6:15 AM
uday fattu
uday fattu - avatar
- 2
for loop is better than while to decrease the length of code
11th Jan 2017, 4:02 AM
ranjith
ranjith - avatar
- 2
there is no much difference between them but for loop is better as compared to while r do while in the way of length of the code written
11th Jan 2017, 4:08 AM
ranjith
ranjith - avatar