6/5/26, 1:19 PM while task1.
py
while [Link]
1 # 1. Print numbers from 1 to 10 and stop when 5 is found
2 i=1
3 while i<=10:
4 if i==5:
5 break
6 print(i)
7 i+=1
8
9 # [Link] numbers from 1 to 20 and stop when 12 is reached.
10 i=1
11 while i<=20:
12 if i==12:
13 break
14 print(i)
15 i+=1
16
17 # [Link] numbers from 1 to 10, skip number 5.
18 i=1
19 while i<=10:
20 if i==5:
21 i+=1
22 continue
23 print(i)
24 i+=1
25
26 # [Link] even numbers from 1 to 20 using continue.
27 i=0
28 while i<=20:
29 if i%2==0:
30 i+=1
31 continue
32 print(i)
33 i+=1
34
35 # [Link] numbers from 1 to 10 using pass.
36 i=0
37 while i<10:
38 pass
39 i+=1
40 print(i)
41
42 # [Link] numbers from 1 to 5 and execute else block.
43 a=1
44 while a<=5:
45 print(a)
46 a+=1
47 else:
48 print("end")
49
50 # [Link] for number 7 in a list using break
51 num=[1,2,3,4,7]
localhost:52499/0b04851b-05fe-4586-b0d5-f9189b8ade42/ 1/3
6/5/26, 1:19 PM while [Link]
52 i=0
53 while i<len(num):
54 if num[i]==7:
55 print("number 7 found at index: ", i)
56 break
57 i+=1
58
59 # [Link] numbers from 1 to 15 except multiples of 3.
60 i=1
61 while i<=15:
62 if i%3==0:
63 i+=1
64 continue
65 print(i)
66 i+=1
67
68 # [Link] first 5 multiples of 4.
69 a=1
70 while a<=4:
71 print("5 *",a,"=",5*a)
72 a+=1
73
74 # [Link] numbers from 10 to 1 and stop of 4.
75 a=10
76 while a>=1:
77 if a == 4:
78 break
79 print(a)
80 a-=1
81
82 # [Link] odd numbers using 1 to 20 using continue.
83 a=1
84 while a<=20:
85 if a%2==0:
86 a+=1
87 continue
88 print(a)
89 a+=1
90
91 # [Link] whether the number is prime using while-else.
92 n = 2
93
94 while n <= 20:
95 i = 2
96 prime = True
97
98 while i < n:
99 if n % i == 0:
100 prime = False
101 break
102 i += 1
103
104 if prime:
105 print(n,"is prime")
localhost:52499/0b04851b-05fe-4586-b0d5-f9189b8ade42/ 2/3
6/5/26, 1:19 PM while [Link]
106
107 n += 1
108 else:
109 print(n,"is not prime")
110
111 # 13. find first number divisible by both 3 and 7.
112 i=1
113 while i<=21:
114 if i%3==0 and i%7==0:
115 print(i)
116 break
117 i+=1
118
119 #[Link] numbers from 1 to 10 skip 3 6 9.
120 i=0
121 while i<=10:
122 if i in (3,6,9):
123 i+=1
124 continue
125 print(i)
126 i+=1
127
128 # 15. print numbers from 1 to 5 and use while-else.
129 i = 1
130 while i <= 5:
131 print(i)
132 i += 1
133 else:
134 print("No..")
135
136
localhost:52499/0b04851b-05fe-4586-b0d5-f9189b8ade42/ 3/3