-
Notifications
You must be signed in to change notification settings - Fork 1
/
#15-loops.py
54 lines (48 loc) · 1.01 KB
/
#15-loops.py
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
# looping in python
# while loop
i = 1
while i <= 10:
print(i)
if i == 3: # when the i's value is equal to 3 break the loop
break
i += 1
# this code describes when i value is 10 close the loop else continue and increment the value
j = 0
while j <= 10:
j += 1
if j == 3: # when the i's value is equal to 3 then continue the loop
continue
print(j)
# with else:
k = 0
while k <= 10:
print(k)
k += 1
else:
print("we can't go beyond 10")
# for loops with if else
myTuple = tuple(("a", "b", "c"))
for x in myTuple:
if x == 'b':
break
else:
print(x)
for y in 'Nunito': # string is itable
print(y)
# with continue
for z in myTuple:
if z == 'b':
continue
else:
print(z)
# using range with start end and gap parameter
for r in range(2, 10, 2):
print(r)
else:
print("finally finished")
# nested for loops
adj = ["red", "big", "tasty"]
fruits = ["apple", "banana", "cherry"]
for a in adj:
for b in fruits:
print(a,b)