2020-01-16 for and while loop

517 ワード

while loop
#while    :
    #     true,    
    #    ,         

n = 1
sum = 0
while n <=10:
    print("n =",n)
    sum = sum +n
    n+=1
print(sum)


for loop
#for    in        :
    #              ,    

for x in [4,1,2]:
    print(x)

for c in "hello":
    print(c)

#range()        

#range(3) = [0,1,2]
#range(5) = [0,1,2,3,4]
#range(3,6)= [3,4,5]
# for x in range(4):
    #print(x)

sum = 0
for x in range(11):
    sum = sum+x
print(sum)