-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfor_else.py
More file actions
43 lines (32 loc) · 838 Bytes
/
for_else.py
File metadata and controls
43 lines (32 loc) · 838 Bytes
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
# Python 3.x program to check if an array consists
# of even number
'''
'''
def contains_even_number(l):
for ele in l:
if ele % 2 == 0:
print ("list contains an even number")
break
# This else executes only if break is NEVER
# reached and loop terminated after all iterations.
else:
print ("list does not contain an even number")
contains_even_number([1, 2, 5])
for n in range(2, 10):
for x in range(2, n):
if n % x == 0:
print(n, 'equals', x, '*', n/x)
break
# Next example
for letter in 'Python': # First Example
if letter == 'h':
break
print ('Current Letter :', letter)
# Third Example
var = 10
while var > 0:
print ('Current variable value :', var)
var = var -1
if var == 5:
break #break always terminates the remaining executions
print ("Good bye!")