How do you constantly keep adding a number to a variable while the program is running

Viewed 25

Recently, I've been developing something and have been wondering how I would constantly keep adding a number to a variable.

For example,

vel = 5

if vel < 1000:
    vel += 1
print(vel)

How would I make it so it would constantly keep adding 1 to the variable vel?

Thanks, I could literally not find this answer anywhere.

1 Answers

Instead of using an if statement, use while loops instead.

vel = 5

while vel < 1000:
    vel += 1
print(vel)
Related