-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWhileLoop.py
More file actions
35 lines (24 loc) · 749 Bytes
/
WhileLoop.py
File metadata and controls
35 lines (24 loc) · 749 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
import random
# Imported one of the libraries to help with while loop example
rand_num = random.randrange(1, 51)
i = 1
# The while loop is looping as long as you have a true statement
while i != rand_num:
i += 1
print("The random value is: ", rand_num)
# Break and continue in while loop
i = 1
# We are going to continue wo cycle through values as long as i
# is less then or equal to 20
while i <= 20:
if i % 2 == 0:
i += 1
# The continue function will ignore everything below in
# while loop and get back to the beginning of this while
continue
if i == 15:
break
# The break function will completely force the code
# to get outside of the while loop
print("Odd : ", i)
i += 1