feat: python loop demo
This commit is contained in:
+32
@@ -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()
|
||||
Reference in New Issue
Block a user