Limiting loop repetition in python -


i have program uses loop, thing though, how can make loop repeat given amount of times? code example below.

while true:     print "this should reprinted ten times" 

how can make code repeat ten, or given amount of times?

you can do:

for in range(10):     print "this should reprinted ten times" 

or

i=0 while < 10:     print "this should reprinted ten times"     i+=1 

or simply

print "this should reprinted ten times\n"*10 

for range , random number:

from random import randint num = randint(5,10) print "this should reprinted {} times\n".format(num)*num 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -