-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)

PlaYZone
  • 1
  • 2
  • 7
    `while True:` ? – Patrick Artner Sep 18 '21 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. – David Sep 18 '21 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. – Blckknght Sep 18 '21 at 17:57
  • @Blckknght `iter(int, 1)`. – no comment Sep 18 '21 at 18:27

1 Answers1

0

You can use

import time
while True:
    time.sleep(1)

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