About 305,000 results
Open links in new tab
  1. loops - When to use "while" or "for" in Python - Stack Overflow

    May 28, 2009 · When I should use a while loop or a for loop in Python? It looks like people prefer using a for loop (for brevity?). Is there any specific situation which I should use one or the other? Is it a mat...

  2. python - What's the exact distinction between the FOR loop and the ...

    Dec 12, 2022 · The major difference between for loop and while loop is that for loop is used when the number of iterations is known, whereas execution is done in a while loop until the statement in the …

  3. Why is looping over range() in Python faster than using a while loop?

    In the while loop, the loop update i += 1 happens in Python, whereas in the for loop again the iterator of range(100000000), written in C, does the i+=1 (or ++i). We can see that it is a combination of both of …

  4. if statement - Python If vs. While? - Stack Overflow

    Apr 14, 2016 · They can't be equivalent because in your first code, only one loop is iterating (the for loop) which checks the if-else statements at each iteration of row_index.

  5. Which loop is faster, while or for? - Stack Overflow

    4 As for infinite loops for(;;) loop is better than while(1) since while evaluates every time the condition but again it depends on the compiler.

  6. python - When to use while loops vs recursion - Stack Overflow

    Jul 5, 2020 · I am a beginner and I am beginning to learn about 'while' statement loops to perform iteration. However, earlier on I learned about 'if/else' statements and how one can perform recursion …

  7. Performance difference between for and while loop in Python

    May 19, 2020 · 5.16 ms ± 69.8 µs per loop (mean ± std. dev. of 7 runs, 100 loops each) The for statement is actually twice as fast as the while loop (a somewhat smaller difference of 1.6 is …

  8. Is there a difference between "pass" and "continue" in a for loop in ...

    116 Yes, there is a difference. continue forces the loop to start at the next iteration while pass means "there is no code to execute here" and will continue through the remainder of the loop body. Run …

  9. Recursion vs loops - Stack Overflow

    Mar 19, 2009 · The only way to get into an infinite loop with an iterative 'for' is to decrement when you should increment or provide the wrong comparison operator for the situation.

  10. What is the time complexity of while loops? - Stack Overflow

    This is equivalent to a for loop, looping the index variable i over the array A. It has O (n). Keep in mind that big-O notation denotes the worst possible time taken by the algorithm, and if the desired element …