About 23,500,000 results
Open links in new tab
  1. Can I make a for loop go forever? (Python) - Stack Overflow

    Nov 17, 2021 · If your for loop takes its data from a generator that runs forever, sure: def infinite(): while True: yield for __ in infinite(): print("Hello") You asked if it could be done as a one-liner.

  2. Are infinite for loops possible in Python? - Stack Overflow

    You can use the second argument of iter(), to call a function repeatedly until its return value matches that argument. This would loop forever as 1 will never be equal to 0 (which is the return value of int()): pass. If you wanted an infinite loop using numbers that are incrementing you could use itertools.count: ....

  3. python - How to run a script forever? - Stack Overflow

    Yes, you can use a while True: loop that never breaks to run Python code continually. However, you will need to put the code you want to run continually inside the loop: #!/usr/bin/python while True: # some python code that I want # to keep on running

  4. Create an infinite loop in Python - CodeSpeedy

    You can create an infinite loop through any method (for or while) by not writing the termination condition or making a termination condition so the loop can never achieve it. For example, in a for loop , you can set the termination condition if the iterator becomes 2.

  5. 6.3. Infinite loopsPython for Everybody - Interactive

    Infinite loops¶ An endless source of amusement for programmers is the observation that the directions on shampoo, “Lather, rinse, repeat,” are an infinite loop because there is no iteration variable telling you how many times to execute the loop.

  6. Python Infinite While Loop - Tutorial Kart

    Python Infinite While Loop. To make a Python While Loop run indefinitely, the while condition has to be True forever. To make the condition True forever, there are many ways. In this tutorial, we will learn some of the ways to create an infinite while loop, with the help of example Python programs. Flowchart – Python Infinite While Loop

  7. Top 4 Types of Statements in Python Infinite Loop - EDUCBA

    An Infinite Loop in Python is a continuous repetitive conditional loop that gets executed until an external factor interferes in the execution flow, like insufficient CPU memory, a failed feature/ error code that stopped the execution, or a new feature in …

  8. How to Run a Python Program Forever? – Be on the Right Side

    Jan 9, 2021 · Challenge: Run a piece of Python code forever—until it is forcefully interrupted by the user. Solution: use a while loop with a Boolean expression that always evaluates to True. Examples: have a look at the following variants of an infinite while loop. # Your Python Code Here. # Method 1: While Condition True while True: # Your Python Code Here.

  9. How to Create Loops in Python (With Examples) - wikiHow

    Feb 20, 2025 · For a loop that goes for a definite amount of times, you will need a for loop, and for a loop that goes on forever you'll need a while loop. You can use the break command to forcibly stop a loop. You can also use continue to skip to the next iteration of the loop. Remember the if, elif and else words for your loops.

  10. How to Create an Infinite Loop in Python - Learning about …

    In this article, we show how to create an infinite loop in Python. An infinite loop that never ends; it never breaks out of the loop. So, whatever is in the loop gets executed forever, unless the program is terminated.

  11. Some results have been removed
Refresh