+ 2
What's the tradeoff in using "While" loop instead of "For" loop?
What is the tradeoff in using the "while" loop instead of the "for" loop?
4 odpowiedzi
+ 6
for loop used widely when you know the initial value, final value and number of times that you do the statements, on the other hand.. (while) is conditional loop, which means it executed if the condition is true, otherwise it stops (number of times that you do the statements is depend on the condition)
+ 5
While loop is better for unknown count of iterations. For example in case you executing something in function or condition, which returns boolean value.
while (stack.Count > 0) {
stack.Pop();
}
+ 1
You use one which best fit your needs.
+ 1
you can use every loop for everything, they are all interchangeable. use the one that you like most or that fits your needs the most