Hello,
I was thinking about giving loops names. And It would be interesting if through this name in a continue or break statement could be called.
A little example what I mean:
loop "outloop" while True:
actmonth = datetime.datetime.now().month
loop "innerloop" for i in range(0, int(input())):
if datetime.datetime.now().month != actmonth:
break "outloop"
else:
print("Waiting for a new Month...")
# Do some stuff if loop ended before new Month
Without giving names it’s always needed to define a new variable and a if statement outside of the innerloop, like this:
while True:
actmonth = datetime.datetime.now().month
shouldend = False
for i in range(0, int(input())):
if datetime.datetime.now().month != actmonth:
shouldend = True
break
else:
print("Waiting for a new Month...")
if shouldend:
break
# Do some stuff if loop ended before new Month
It’s possible without it, but it is more readable.
Maybe another option is, but that’s too deep, to make loops to objects.
Best Regards,
Oskar Promeuschel