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

    Dec 27, 2022 · First of all there are differences between the for loop in python and in other languages. While in python it iterates over a list of values (eg: for value in [4,3,2,7]), in most …

  2. Python while loop inside while loop - Stack Overflow

    Mar 28, 2013 · You've forgotten to reset the value of num (and also even and odd) inside the outer while loop (before starting the while num < 100 loop). Second time in, it doesn't need to …

  3. While loop with if/else statement in Python - Stack Overflow

    Apr 25, 2016 · password is not an input equal to string "your password", which makes the while expression True, while true repeat. if password does equal 'your password' expression is false, …

  4. python - How can I stop a While loop? - Stack Overflow

    You need to understand that the break statement in your example will exit the infinite loop you've created with while True. So when the break condition is True, the program will quit the infinite …

  5. python - How to emulate a do-while loop? - Stack Overflow

    Here's a very simple way to emulate a do-while loop: condition = True while condition: # loop body here condition = test_loop_condition() # end of loop The key features of a do-while loop are …

  6. How to break out of while loop in Python? - Stack Overflow

    Nov 11, 2024 · It's bad programming." While I try to avoid them as a general rule, many times I have simplified logic structures in a while loop simply by using a single break statement. While …

  7. python: restarting a loop - Stack Overflow

    Feb 16, 2016 · Just wanted to post an alternative which might be more genearally usable. Most of the existing solutions use a loop index to avoid this. But you don't have to use an index - the …

  8. Time a while loop python - Stack Overflow

    Feb 7, 2013 · Right idea, but your placement of the timing functions is a wee bit off, I've corrected it here: import random import time import sys def main(): looperCPU = 500 start = time.time() …

  9. python - Which of "and" or "or" should I use to join non-equality ...

    If DieOne rolled a 4 and DieTwo rolled a 6, the while loop will run because DieOne != 6 is true, and DieTwo != 6 is false. I put this train of thought into code below. while DieOne != 6 or …

  10. Python: Continuing to next iteration in outer loop

    May 30, 2011 · Interesting. I agree with Guido here. While it would be nice for some cases it would be abused. Another reason for not implementing it is that right now it is pretty straight …

Refresh