You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: basics/loops.py
+18-3Lines changed: 18 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -70,7 +70,22 @@
70
70
goodbye
71
71
"""
72
72
"""
73
-
-------------
73
+
---------------
74
74
EXAMPLE 3
75
-
-------------
76
-
"""
75
+
---------------
76
+
"""
77
+
whileTrue: # This wraps the code in a loop
78
+
print("Press a 1 to loop and 2 to exit") # Print the question on the screen for the user
79
+
press=input("> ") # Input the user or ask the user to type the number of the above screen
80
+
ifpress=="1": # if the user types 1
81
+
print("This is a loop") # The program will print this is a loop and loop again
82
+
elifpress=="2": # If the user types 2 then break or exit the loop
83
+
break# This breaks the loop
84
+
else: # if the user types anything else other than 1 or 2 it will say Incorrect option selected and loop again until the until the user presses 2 to exit
0 commit comments