feat: python loop demo

This commit is contained in:
xpk
2025-11-25 10:59:00 +08:00
parent 6c01a4f55c
commit 7e6e33397d
+32
View File
@@ -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()