Files
code-dumps/py/loops.py
T
2025-11-25 10:59:00 +08:00

33 lines
633 B
Python

#!/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()