Days_16 Make it Stop!
Ari Wira Saputra
Posted on March 28, 2023
Assuming you are writing code, "while true" is a programming construct that creates an infinite loop. The code within the loop will be executed repeatedly until a condition is met to break out of the loop.
# All About the Loop
#
#28 MARCH 2023
class repet():
def __init__(self,goAgain,answer,counter,addAnother):
self.goAgain = goAgain
self.answer = answer
self.counter = counter
self.addAnother =addAnother
def methode(self):
while True:
print("This program is running")
self.goAgain = input("Go again?: ")
if self.goAgain == "no":
break
print("Aww, I was having a good time")
def methode1(self):
while True:
self.counter = 0
self.answer = int(input("Enter a number: "))
print("Adding it up!!! ")
self.counter += self.answer
print("Current total is",self.counter)
self.addAnother = input("add another? ")
if self.addAnother =="no":
break
print("Bye!!!")
def call():
t = repet("",0,"", "")
t.methode()
t.methode1()
call()
It's important to be careful when using infinite loops in your code, as they can cause your program to become stuck and unresponsive if there is no way to break out of the loop.
💖 💪 🙅 🚩
Ari Wira Saputra
Posted on March 28, 2023
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
githubcopilot AI Innovations at Microsoft Ignite 2024 What You Need to Know (Part 2)
November 29, 2024