-
Notifications
You must be signed in to change notification settings - Fork 282
/
Copy pathtutorial18_automating_using_while_loops.py
65 lines (39 loc) · 1.22 KB
/
tutorial18_automating_using_while_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
55
56
57
58
59
60
61
62
63
64
65
#Video Playlist: https://www.youtube.com/playlist?list=PLHae9ggVvqPgyRQQOtENr6hK0m1UquGaG
"""
while: do something while a condition holds true
for: do things for multiple times , especially in lists or strings
for and while loops can also be nested.
"""
### WHile
count = 0
while count<10:
print("The count is:", count)
count = count + 1
#Be warned of infinite loop...
count = 0
while count==0:
print("Oh my god I got stuck")
#You can use break statement even if the while condition is true
count = 0
while count<10:
print("The count is:", count)
if count ==5:
break
count = count + 1
#Continue: USe continue to stop current iteration, continue with next.
#Here if count = 5 it skips (continues) and moves on.
count = 0
while count<10:
count = count + 1
if count ==5:
continue
print("The count is:", count)
## Let's automate Centigrade to F conversion for some values
#from -40 to 40 with steps of 5
#F = (9/5)C + 32
C = -40
while C <= 40:
F = ((9./5)*C) + 32
print(C, "C in Fahrenheit is: ",F, "F")
C = C + 5
####################################