About 76,700 results
Open links in new tab
  1. python - How do I write a loop to repeat the code? - Stack Overflow

    You can create a variable, and then say that as long as the variable is true to its value, to repeat the code in the for loop.

  2. How To Use The Repeat() Function In Python?

    Jan 4, 2025 · Learn how to use Python's `repeat ()` function from the `itertools` module! This tutorial covers syntax, examples, and tips for repeating values in loops.

  3. Loops in Python - For, While and Nested Loops - GeeksforGeeks

    Mar 8, 2025 · Loops in Python are used to repeat actions efficiently. The main types are For loops (counting through items) and While loops (based on conditions). Additionally, Nested Loops …

  4. loops - Python: How to keep repeating a program until a specific …

    There are two ways to do this. First is like this: inp = raw_input() # Get the input. if inp == "": # If it is a blank line... break # ...break the loop. The second is like this: inp = raw_input() # Get the …

  5. How to Repeat N times in Python? (& how to Iterate?) - FavTutor

    Oct 25, 2022 · In this article, we've discussed how to repeat in Python and how it brought up the need for loops and functions. Further, we've learned about repeat () functions in python, …

  6. python - How to repeat a for loop - Stack Overflow

    Sep 13, 2015 · Try using a while loop instead: i += 1. if i == 4: i = 0. The same logic can be implemented with: for i in range(4): print(i) Or using the modulo operator which is common …

  7. SOLVED: How to loop n times in Python [10 Easy Examples]

    Jan 9, 2024 · First one is to iterate over the sequence like List, Tuple, Set and Dictionary. And the other one is to iterate over the range of numbers. This version of for loop will iterate over a …

  8. How to repeat a function N times or indefinitely in Python

    Feb 16, 2023 · To repeat a function indefinitely in Python, you need to use the while loop and call the function in that loop. To stop the function, you need to write an if statement with a condition …

  9. How to Repeat Code N Times in Python - Delft Stack

    Feb 14, 2021 · In this article, we’ve explored five methods to repeat a string of code N times in Python: using for loops, while loops, the itertools.repeat() function, list comprehension, and …

  10. Loops in Python with Examples

    Loops are constructs that repeatedly execute a piece of code based on the conditions. See various types of loops in Python with examples.

  11. Some results have been removed
Refresh