#just repeatedly do ten times
for i in range(0,10):
    print "*"

#each time print more stars
for i in range(0,10):
    print "*"*i


#each time print less stars
for i in range(0,10):
    print "*"*(10-i)

#it could be funny
for i in range(0,10):
    print "*"*i+" "*3+"*"*(10-i)

#loop index i is not use in the loop command, nothing is changed.
a=5
for i in range(0,10):
    print "*"*a

for i in range(0,10):
    print i

for i in range(0,10):
    print i, i*i

#we can iterate through i
for i in range(0,10):
    print i**0.5,i, i**2, i**3

#format is not good. use rjust() a string function.
#use str and float to convert data type to str and float

print 'square root'.rjust(15),'integer'.rjust(10), 'square'.rjust(10), 'cubic'.rjust(10)
for i in range(0,10):
    print str(float(i)**0.50).rjust(15),str(i).rjust(10), str(i**2).rjust(10), str(i**3).rjust(10)

"""
Explanation: Looping technique: while and for
For and while are means that we want to ask computer to do task repeatedly.
 but each with slightly different problems.
End of explanation
"""


#comparator and logic and/or
a=10
print a<20
print a<20 and a>5
print a<20 or a<12
print 12<a<20

a=10
while a<20:
    print a
    a=a+1

#if we set the wrong conditions, loop command will never be excute.
#nothing will be printed
a=10
while a==20:
    print a
    a=a+1

#if we do no change loop index, it will execute forever.
#following code will never stop
#do not run.
a=10
while a<20:
    print a


#while could be used just like a for loop
a=0
while a<10:
    print a
    a=a+1

#while could be used just like a for loop
#be careful while you change the loop index
a=0
while a<10:
    print a
    a=a+1
    a=a*2

#check if a is a prime
# we can use a flag to trig the exit immediately, save time
a=131
i=2
found=False
is_prime=True
while (i<a) and found==False:
    print i, " : testing......"
    if a%i==0:
        print a," = ", i, " * ",a/i
        found=True
        is_prime=False
    else:
        #print i,"can not divide ", a
        found=False
    i=i+1
#note that once a%i=0, the while loop just stop/exit

print "Prime  => ",is_prime

#check if a is a prime
# we can use a flag to trig the exit immediately, save time
#actually we do not have to check till a-1, sqrt(a) is enough
a=131
i=2
found=False
is_prime=True
while (i<float(a)**0.5) and found==False:
    print i, " : testing......"
    if a%i==0:
        print a," = ", i, " * ",a/i
        found=True
        is_prime=False
    else:
        #print i,"can not divide ", a
        found=False
    i=i+1
#note that once a%i=0, the while loop just stop/exit

print "Prime  => ",is_prime

"""
Explanation: While loop
While loop is more flexible. But we need to 
1. initialize it before entering the loop 
2. set the continue conditions
3. change the loop index to tigger the stop condition
End of explanation
"""


test

"""
Explanation: While and For are powerful loop tools, we can use them to do repeated operation. Pay attention to 
1. the loop index: what is actually changed during each execution.
2. pay attention to the conditions to test.
3. pay attention how to start and how to stop.
End of explanation
"""


