How to interpret this dancing code in Python? - Infinite Loop

python

#1

Hello Guys

I found this amazing code in Python which gives an usual output. Here is the code:

while True:
      for i in ["/","-","|","\","|"]:
           print "%s\r" % i,
     #Press Enter     
     #Press Enter again, if required 
     #See the Dance

While you people have fun while writing this code, can someone please interpret this for me. I am unable to understand it.
How can I exit out of this without closing the program?

Regards
Indu


#2

@indutaneja11, it’s, in principle, an infinite loop, so you cannot escape it without somehow interrupting it. (You can however modify the program so that it breaks out when some condition is met.) What it does, essentially, is loop over the characters in the list: after printing one it does a carriage return (the \r part) and prints the next. Pressing Enter forces the loop to proceed in a new line.