5 июня 2024
You use for loop, when you know how many iterations you are going to do, for example you want to loop a list that contains numbers: [1, 2, 3, 4, 5].
This case you know how many times you are going to loop (5) times. And then it will exist the loop and continues execution
You use while loop when you don't know how many times you'll execute the code, for example let's say you want to ask the user for an input number and then you print('The number you typed is', number).
But if the user enter "x", you should exist loop:
while True:
number = int(input('Enter number'))
If number == 0:
break
Print('Number is ', number)
🌟 Exciting News! 🌟
I’m happy to announce that one of my side projects has officially made it to production! 🎉
Introducing RevampedCV(revampedcv.com) – an AI-optimized resume builder designed to help you create standout resumes effortlessly. Our tool is simple, user-friendly, and effective.
Check it out at revampedcv.com and let me know what you think!
Your feedback is highly appreciated. 🙌