For and While Loop
eharetea

The very basics of for and while loops in Python.

Loops!

Date Created:Friday December 29th, 2006 03:41 AM
Date Modified:Friday August 01st, 2008 01:22 AM

# for and while loop

>>> thepath = thepath.replace('/',' ')
>>> folders = []
>>> for x in thepath:
...     folders.append(x)
...
>>> while folders:
...     folders = folders[1:]
...     print folders
...
['u', 's', 'r', ' ', 'h', 'o', 'm', 'e', ' ', 'd', 'l', 'y', 'n', 'c', 'h']
['s', 'r', ' ', 'h', 'o', 'm', 'e', ' ', 'd', 'l', 'y', 'n', 'c', 'h']
['r', ' ', 'h', 'o', 'm', 'e', ' ', 'd', 'l', 'y', 'n', 'c', 'h']
[' ', 'h', 'o', 'm', 'e', ' ', 'd', 'l', 'y', 'n', 'c', 'h']
['h', 'o', 'm', 'e', ' ', 'd', 'l', 'y', 'n', 'c', 'h']
['o', 'm', 'e', ' ', 'd', 'l', 'y', 'n', 'c', 'h']
['m', 'e', ' ', 'd', 'l', 'y', 'n', 'c', 'h']
['e', ' ', 'd', 'l', 'y', 'n', 'c', 'h']
[' ', 'd', 'l', 'y', 'n', 'c', 'h']
['d', 'l', 'y', 'n', 'c', 'h']
['l', 'y', 'n', 'c', 'h']
['y', 'n', 'c', 'h']
['n', 'c', 'h']
['c', 'h']
['h']
[]
>>>