+ 7

Loop battle:which loop do you prefer most 'for' or 'while'??? And your opinion....

11th May 2018, 5:12 PM
Yash Nirmal
Yash Nirmal - avatar
10 Antworten
+ 5
while loop is the best
11th May 2018, 5:20 PM
Shahil Ahmed
Shahil Ahmed - avatar
+ 5
actually they both can be used to perform the very same task, but for a learner (it was my experience when i started learning loops) it was easy to understand while loop and thats the only advantage while loop has
11th May 2018, 5:23 PM
Shahil Ahmed
Shahil Ahmed - avatar
+ 5
yeah once you mastered loop its great to use for loop to shorten your work
11th May 2018, 5:31 PM
Shahil Ahmed
Shahil Ahmed - avatar
+ 4
i think its for loop...
11th May 2018, 5:21 PM
Yash Nirmal
Yash Nirmal - avatar
+ 4
ooohhh... i understand...
11th May 2018, 5:23 PM
Yash Nirmal
Yash Nirmal - avatar
+ 4
The answer is --> I'll use whichever loop I'll find most suitable in my current problem. That's the whole game, isn't it ?
11th May 2018, 5:39 PM
Aaron Stone
Aaron Stone - avatar
+ 3
thanks all for your advices..😊😊
12th May 2018, 8:02 AM
Yash Nirmal
Yash Nirmal - avatar
+ 2
Typically, you would want to use a for loop when you have a determinate number of iterations and a while loop when you have an indeterminate number of iterations. For example, if you’re iterating through an array, you should usually know how many times you’ll loop. If you’re reading through a file, you don’t necessarily know when the reading should end - you would stop at the point of reaching EOF.
11th May 2018, 5:38 PM
MsJ
MsJ - avatar
+ 1
hi, for and while loops are the most generous loops. for statements takes the shorter path while, while loops takes the longer road to comply. so , my friends regards to the program we are creating shorter roads are more interesting than longer one. ! HAPPY CODDING !
14th May 2018, 2:14 AM
Rajeeb
+ 1
If I have to drive my vehicle for 5kms ,I'll choose for loop and if I have to drive my vehicle until I'm out of fuel, I'll use while loop.. hope you get that
14th May 2018, 4:27 PM
Shivam Papat
Shivam Papat - avatar