Created
November 12, 2024 02:30
-
-
Save yeiichi/f134bea394142754108b6f97033dbefc to your computer and use it in GitHub Desktop.
Mimic do-while loop with an emergency brake feature.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
"""Mimic do-while loop with an emergency brake feature. | |
""" | |
def dummy_func(): | |
for i in range(8): | |
yield i | |
def main(): | |
num = dummy_func() | |
emergency_break_max = 12 | |
emergency_break_sts = 0 | |
while True: | |
# begin: main body | |
try: | |
print(next(num)) | |
except StopIteration: | |
print('\033[31mLoop Runaway!\033[0m') | |
# end: main body | |
emergency_break_sts += 1 | |
if emergency_break_sts > emergency_break_max: | |
print('\033[93mEB Applied\033[0m') | |
break | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment