Ask coding questions

← Back to all posts
How do you make a repeat function
mcconnorea

Its python that I'm using and I need a function to repeat something forever so the user can keep using it

Voters
mcconnorea
Comments
hotnewtop
Coder100

there are many ways to do this.

  1. recursion

You might get a stack overflow if you don't pause for a bit, because it will repeatedly call itself over and over again.

  1. while loop
    this repeats forever, you can use break to exit.
  1. for loop
    this repeats for x amount of times:

change x to how many times.

MrVoo

This doesn't repeat forever, but seeing as you already got answerd, it's good to know:

mcconnorea

thank you @MrVoo

CodingElf66

Do the following code:

Now you can mark it as answered

Spacecraft

put your code inside a while loop like this: