Control Structures of Python
 


If, While, For

# basic "If"

if boolean:
x = 1
else:
x = 0

#While loop

while i < 100:
i + 1

# Basic For Loop

for x in range(0, 100):
dosomething(x)

# Continue
nlist = []
for i in xrange(0,100):
if i == 0:
continue
nlist.append( 7 / i )

# Break
heads = 0
while 1:
if x = 0:
break
else:
x = random.rand(0,1)
heads += 1

# Case
age = raw_input("Enter Your Age:")
if age < 5:
print "You're too young!"
elif age = 6:
print "You can enter school!"
elif age = 18:
print "You can get a job!"
else: # Default case
print "We are not sure!"

(c) Shilpa Sayura Foundation 2006-2017