Skip to content
Sign upLog in

Loops

Profile icon
MATTHEWBECHTEL

Does anyone now how to loop something?

You are viewing a single comment. View All
Profile icon
ArchieMaclean

python:

# does 10 times for n in range(10): print(n) myarray = ["a","b","c"] # repeats for each item in the array for item in myarray: print(item) x = 0 # conditional loop while x<100: print(x) x+= 1 # loop forever (don't do this unless you know what you're doing, a # nd you're limiting how fast you can go through it) while True: print("oh dear, repl crashed")

Please upvote if this helps :)

Profile icon
MATTHEWBECHTEL

I will try it. Thanks.

@ArchieMaclean

Profile icon
MATTHEWBECHTEL

Hm. I am not sure if it is perfect but definitely a nice start. Thank you.

@ArchieMaclean

Profile icon
ArchieMaclean

@MATTHEWBECHTEL
what do you mean? Is it not working for you?

Profile icon
MATTHEWBECHTEL

No it’s fine but my keyboard is lagging. Thanks.

@ArchieMaclean

Profile icon
ArchieMaclean
Profile icon
MATTHEWBECHTEL

Is there a way to loop a certain Message though?

Profile icon
MATTHEWBECHTEL

Never mind, I fixed it. But do you think it will lag itself to death before it reaches 10k messages?

@ArchieMaclean

Profile icon
Murzikal

@MATTHEWBECHTEL
as in a print statement? then do

while True: print("your message")
Profile icon
ArchieMaclean

@MATTHEWBECHTEL
If you want to do a giant loop, you can use xrange, like:

for n in xrange(100000): # do something

IDK what you mean by 'Message' though