-2

I know you can just do this (technically):

import time
variable = 0 
while variable < 99999999999999999999999999999999999999
  variable = variable + 1
  time.sleep(1)

But is there just a way to make an infinite loop without typing all those 9's? (idk if this makes sense but I'm sure you get what I mean)

4
  • 7
    while True: ? Commented Sep 18, 2021 at 17:52
  • All you need is a condition that will always be true. 1 == 1 will always be true. True will always be true. Etc. Your variable < 99999999999999999999999999999999999999 condition will also always be true if you don't increment variable 99999999999999999999999999999999999999 times. Commented Sep 18, 2021 at 17:54
  • You can also use a for loop, you just need an infinite iterable. There are a few of those in the Python standard library, like itertools.count, which counts up like the variable in your question: for variable in itertools.count(): will count up forever, just in case you actually need that. Commented Sep 18, 2021 at 17:57
  • @Blckknght iter(int, 1). Commented Sep 18, 2021 at 18:27

1 Answer 1

0

You can use

import time
while True:
    time.sleep(1)

Because you want an infinite loop with a one-second delay between iterations.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.