-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathforLoop.py
More file actions
66 lines (57 loc) · 1.26 KB
/
forLoop.py
File metadata and controls
66 lines (57 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
'''
@Author : Md. Shamimul Islam
@Written : 10/02/2019
@Description: python For Loop
'''
sequence=[55,3,2,None,0,10,None]
total=0
for value in sequence:
if value is None:
continue
else:
total+=value
print(total)
seq=[1,2,3,0,8,1,7,5]
total=0
for value_5 in seq:
if value_5==5:
break
else:
total+=value_5
print(total)
# Iterating over a list
print("-------------List Iteration------------")
m=['i','am','miuan']
for i in m:
print(i)
# Iterating over a tuple
print("-----------------tuple Iteration------------------")
n=('u','are','great')
for i in n:
print(i)
l=['i','love','u']
for i in range(len(l)):
print(l[i])
else:
print("it is ok")
print("------nested for loop------------")
for i in range(4):
for j in range(4):
if j>i:
break
print(i,j)
print("-------control flow-------------")
# It returns the control to the beginning of the loop.
# Prints all letters except 'e' and 's'
for i in "bangladesh":
if i=="s" or i=="a":
continue
print("current letter",i)
#It brings control out of the loop
# break the loop as soon it sees 'e'
# or 's'
print('------2----------')
for i in "bangladesh":
if i=="s" or i=="a":
break
print(i)