diff --git a/py/loops.py b/py/loops.py new file mode 100644 index 0000000..a4507fc --- /dev/null +++ b/py/loops.py @@ -0,0 +1,32 @@ +#!/usr/bin/python3 +r""" +Python loops demo + +License: This program is released under the MIT License +""" +import logging +logging.basicConfig(level=logging.INFO, format="%(funcName)s %(levelname)s: %(message)s") + +def while_loop() -> None: + counter: int = 1 + while counter <= 5: + logging.info(counter) + counter += 1 + +def for_loop() -> None: + for i in range(5): + logging.info(i) + +# Main function +def main() -> None: + """ + Both functions will log a message 5 times, but the for loop is so much simpler + + """ + while_loop() + for_loop() + + +# Call main function +if __name__ == '__main__': + main()