In [ ]:
In [2]:
x = [1,2,3,4,5,6,7,8]
for item in x:
print item
In [3]:
s = ['a','c','b','d','e','g','h',8]
for item in s:
print item
Range function in python is a daily-use function in the for loop:
In [4]:
for item in range(1,20,2):
print item
This is a simple for loop that sum up all squared integer from 1 to 100
In [5]:
s=0
for i in range(1,100):
s+=i*i
print s
In [6]:
s=0; i=1
while i<100:
s+=i*i
i+=1
print s
In [8]:
m = 20
n = 79
while n != 0:
r = m % n
m = n
n = r
print m
In [ ]: