-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path18_WhileLoops.py
More file actions
36 lines (31 loc) · 959 Bytes
/
Copy path18_WhileLoops.py
File metadata and controls
36 lines (31 loc) · 959 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
# i = int(input("Enter the number: "))
# while i <= 38:
# i = int(input("Enter the number: "))
# print(i)
# # i = i + 1
# print("Done with the loop")
# count = 5
# while (count > 0):
# print(count)
# count = count - 1
# count = 5
# while count > 0:
# print(count)
# count = count - 1
# else:
# print("I am inside else")
# -----------------------------------------------
# Python does not have a built-in do...while loop.
# We can simulate it using while True + break.
# The behavior:
# - Loop body executes at least once
# - Then condition is checked to possibly exit
# -----------------------------------------------
# Simulating do { ... } while(condition)
while True:
# Loop body: get input from the user
num = int(input("Enter a number: "))
print("You entered:", num)
# Condition check (like while-condition in do..while)
if num < 0: # Stop the loop if negative number is entered
break