0% found this document useful (0 votes)
11 views2 pages

Ch4 Loops

Uploaded by

ztrk.seray
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views2 pages

Ch4 Loops

Uploaded by

ztrk.seray
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

# # # iteration

# # x = 10
# # x = x + 1
# # X = x + 2 # iterate by adding two each time
# # # while statement
# # n = 5
# # while n > 0: # if this statement is false get out of the while statement
# # print(n)
# # n = n - 1 # if we forget this part, infinite loop
# # print('Blastoff!!!')
# #
# # # Example of infinite loop
# # # n = 10
# # # while True:
# # # print(n,end=' ')
# # # n = n - 1
# # # print('Done!!')
#
# while True: # infinite loop
# line = input('> ')
# if line == 'done':
# break # break condition
# print(line)
# print('Done!')
#
#
# # finishing iterations with continue
# while True:
# line = input('> ')
# if line[0] == '#':
# continue # move on to the next iteration
# if line == 'done':
# break # get out of the loop
# print(line)
# print('Done!')

# for loop
# friends = ['Mehmet','Ali','Ahmet'] # a list of values or names
# for friend in friends:
# print('Happy new year ', friend)
# print('done!!!')
#
# for x in friends:
# print('Happy new year ', x)
# print('done!!!')

# for i in range(10): range kullanarak


#
# count = 0
# SUM = 0
# for itervar in [3, 31, 9 ,13, 100]:
# print(itervar)
# count = count + 1 # a counter for the number of iterations
# SUM = SUM + itervar
# print('Number of iterations: ', count,' The total is ', SUM)
#
# total = 0
# for itervar in [3, 31, 9 ,13, 100]:
# total = total + itervar
# print(total)
# print('Total: ', total)

# total = 0 # let's use the range function


# x = [3, 31, 9 ,13, 100] # a list type
# for i in range(len(x)): # len() function returns the length of the array
# print(i)
# total = total + x[i] # access the elements of x by index
# print('Total: ',total)

largest = None
print('Before:' ,largest)
for itervar in [3, 31, 9 ,13, 100,200,1000]:
if largest is None or itervar > largest:
largest = itervar
print('Loop:',itervar,largest)
print('Largest:',largest)

You might also like