#while loop = perform some code WHILE some condition remains true # ---------------- EXAMPLE 1 ---------------- name = input("Enter your name: ") while name == "": print("You did not enter your name!") name = input("Enter your name: ") print(f"Hello {name}") # ---------------- EXAMPLE 2 ---------------- age = int(input("Enter your age: ")) while age < 0: print("Age can't be negative") age = int(input("Enter your age: ")) print(f"You are {age} years old") # ---------------- EXAMPLE 3 ---------------- food = input("Enter a food you like (q to quit): ") while not food == "q": print(f"You like {food}") food = input("Enter another food you like (q to quit): ") print("bye") # ---------------- EXAMPLE 4 ---------------- num = int(input("Enter a # between 1 - 10: ")) while num < 1 or num > 10: print(f"{num} is not valid") num = int(input("Enter a # between 1 - 10: ")) print(f"You picked the number {num}")
Hi, i tried the first example, i have exactly what you have but if i enter a name it doesnt print the f string, it just ends, if i dont put anything that part works
Thank you very much, this is the first time I have actually completely understood how to implement a while loop without having to deal with infinite responses. Your video was great and helped a lot. Cheers
Wow. Thats what I needed!!!! I am learning and learning loops and anyway can't understand how it's works. Maybe now I will. Thanks Bro! Now I need to find you video for for loop as well ;)
Bro, i just spend a lot of time searching how to exit a while loop with one key and did not finding anything that make some sense to me and you explained it in six minutes, thanks a lot!
OMG MAN THANK YOU SOOO MUCH THIS VID IS A LIFE SAVER! My comp science master's thesis is due tomorrow and I hadn't even selected my cites or refs until now!
thank you very much for the best explaining even our professor could not explain such good as you for 6 min i understood everything that we were learning for 1 week
This was really an interesting video in term of learning python and whole the tutorial is really appreciated just for helping us giving detailed information........................................
Not necessarily. if a while loop exits due to the condition being false, the upcoming lines of code will be executed. Loops can either be exited with the while condition being false, or with the help of 'break' #example: i=1 while i in range(6): print(i) i+=1 if i==6: break else: print("no break") In this code, since break is used to exit the loop, the else statement doesn't get executed. but if the if block is commented out, you could see that it runs the else statement after the loop gets exited.
So basically for example one if the user does not input their name, the while loop will keep asking for the user name until the condition is true and print out hello to the user
thanks for making this video, name = input("Please enter your name and no symbols or number: ") while name.isalpha() == False: print("You have either enter a number or symbol in your name, please try again:") name = input("Please enter your name and no symbols or number: ") else: print(f"Hello there {name}, thank you for following instructions")
hello sir, why my computer when running infinite loop such like your video in 2:14 caused my mac so hot (%CPU about 300%)? i'm using python from conda, vs code, and macos ventura
@@abdevil2330 but some of my other machine, let say intel mac doesnt get so hot, but the performance also slower than this silicon mac, i dont know if the configuration is the problem or what. let say the other machine (my android, running python with pydroid3) also doesnt get hot neither crash.
enter = input("Would you like to say your favourite food? (y/n): ") while enter == "y": food = input("Enter your favourite food: ") enter = input("Would you like to say another favourite food? (y/n): ") print("Thanks for stopping by!")
#while loop = perform some code WHILE some condition remains true
# ---------------- EXAMPLE 1 ----------------
name = input("Enter your name: ")
while name == "":
print("You did not enter your name!")
name = input("Enter your name: ")
print(f"Hello {name}")
# ---------------- EXAMPLE 2 ----------------
age = int(input("Enter your age: "))
while age < 0:
print("Age can't be negative")
age = int(input("Enter your age: "))
print(f"You are {age} years old")
# ---------------- EXAMPLE 3 ----------------
food = input("Enter a food you like (q to quit): ")
while not food == "q":
print(f"You like {food}")
food = input("Enter another food you like (q to quit): ")
print("bye")
# ---------------- EXAMPLE 4 ----------------
num = int(input("Enter a # between 1 - 10: "))
while num < 1 or num > 10:
print(f"{num} is not valid")
num = int(input("Enter a # between 1 - 10: "))
print(f"You picked the number {num}")
thank u soo much bro for the video as well as the code here☝
Thank you for your efforts 🤩!!
Hi, i tried the first example, i have exactly what you have but if i enter a name it doesnt print the f string, it just ends, if i dont put anything that part works
This cleared all my doubts
Thank you sir for your effortss !!!!
You explained this so clearly. Easiest “while” video to understand for me thus far. Liked.
This*
@@buenolvrthus is grammatically correct here
@@buenolvr if it said this it would be incorrect. dafuq
innit bro this guy is brilliant
@@_Debs_16 broo isd idk what the hell ts was till i saw this vid
As a senior (citizen.) trying to learn Python on YT I must say this is the clearest explanation of while loops I have seen todate. Thank you so much.
You aint a senior dude.
seniors dont say YT bro
quit fooling
Ditto. (Both as to senior (73) and the clarity of the explanation.)
Schools gonna be outta business-thank you so much- clear and precise teaching
Thank you so much for this video! I have been stuck on while loops for two days. I understand it so much more now. You rock!
are u a computer
@@buenolvr 😂
Thank you very much, this is the first time I have actually completely understood how to implement a while loop without having to deal with infinite responses. Your video was great and helped a lot. Cheers
This was the best explanation video so far that i found. And probably the best Coding based teaching YT I have came across.
You are one of the best tutor in youtube for Python tutorials.
i can show u a toutoriaalalaalal
you are the only one in yt who explain correctly
You became my favourite coder and teacher💯❤️🤝😊
its proggraming!!
Following from Uganda , This is the best explanation have received . finally understood while loops
Showing this to my girlfriend who is learning to code. Thanks!!
Wow. Thats what I needed!!!! I am learning and learning loops and anyway can't understand how it's works. Maybe now I will. Thanks Bro!
Now I need to find you video for for loop as well ;)
man you explained this so clearly it makes me wonder why I’m having so much difficulty with it
This is very nice video, very clear, which is what I (just another regular viewer who tries to learn Python) want to see
best tutor, even better than my computing teacher🤣
NICELY DONE BRO...❤
Bro, i just spend a lot of time searching how to exit a while loop with one key and did not finding anything that make some sense to me and you explained it in six minutes, thanks a lot!
Thanks!! I stuck in while loop as well. Now I understand how it works.
OMG MAN THANK YOU SOOO MUCH THIS VID IS A LIFE SAVER! My comp science master's thesis is due tomorrow and I hadn't even selected my cites or refs until now!
excellent explanation, thanks
Good one sir
I understanted so very well, you explain better than 99% people in this world, many thanks!
I've been in tech studies for long time but now I came to fully understand how while loop works
I'm not even learning python, this is just good programming explanation, thank you!
Your youtube channel has been real helpful, thank you!
Finally a video that explains it from scratch with easy examples rather than rocket science
This is the best python tutorial so far, I read a book but I couldn't understand clearly
thanks man , it looked so easy but it is actually tough when we learn it for the first time .
bro, you is the best
i'm getting a lot better
thanks
The best video to explain the while loop ever
Bro. Now this is bro code. You are a good teacher👌👌👌👌
thank you very much for the best explaining even our professor could not explain such good as you for 6 min i understood everything that we were learning for 1 week
This was really an interesting video in term of learning python and whole the tutorial is really appreciated just for helping us giving detailed information........................................
honstly salute to you si. this is far by the easiest explanation of while loops
I now understand while loops better after watching this thank you
I was having a tough time understanding while loops in my intro class, but this was so helpful. Thank you!
Finally, an easy explanation! Thank you!
Bro your courses saving lives
Thank you very much now I'm learning data science course it will be more useful for me to understand the python programming language very easily
Really enjoy your videos. Great work.
bro, i love you. you literally did just saved me
Best Vid to understand the while Loop. Great job
simple yet very clear and easy to understand.. thank you so much
Thank you to help us improve our programing
Thanks! This has been the best and easiest tutorial for me to understand 👏 The explanation is quit simple and clear to the point. 🔥
I've been finding it so difficult when it comes to while loops, you made this so easy thank you!
But is it not necessary to use else: statement??
Not necessarily. if a while loop exits due to the condition being false, the upcoming lines of code will be executed.
Loops can either be exited with the while condition being false, or with the help of 'break'
#example:
i=1
while i in range(6):
print(i)
i+=1
if i==6:
break
else:
print("no break")
In this code, since break is used to exit the loop, the else statement doesn't get executed. but if the if block is commented out, you could see that it runs the else statement after the loop gets exited.
BEST TUTORIAL EVER! THANK YOU SO MUCH MY EXAM IS TOMMOROW
A very concise explanation as expected.
So basically for example one if the user does not input their name, the while loop will keep asking for the user name until the condition is true and print out hello to the user
if you put the command again of asking names
well explained
thanks for making me understand about while loop
appreciated
This makes so much sense now. Thank you Bro Code.
I've been working on this from months and you made me understand in minutes 😍
Excellently explained
Easy explanation so far .. ♥️
Thanks bro! You're helping me a lot
What an informative video!! I find this video super helpful with such clear explanations!! Thank yoou so much!
The real sigma
Charity donar + high quality, quantity videos ❤
Great 🎉
You need put this whole python videos to compilation so we know tools about python
You explained soo clearly , i have a test tomorrow on this chapter and this video helped a lot , thankyou
good luck on your test. i got exam in jan coming up for coding in python.
Bro explains as good as networkchuck in a unique way.
thanks for teaching me the WoW loop :)
thanks for making this video,
name = input("Please enter your name and no symbols or number: ")
while name.isalpha() == False:
print("You have either enter a number or symbol in your name, please try again:")
name = input("Please enter your name and no symbols or number: ")
else:
print(f"Hello there {name}, thank you for following instructions")
Best Bro 😀
This tutorial helped so much with understansding the for while loop
You made it so easy . Thanks bro ❤
Beautiful! YOU ARE THE BEST!!!
great video
Thanks for the help, much better than coursera's courses, and their explanation on loops in general. Subscribed!
you are really a Bro for teaching us while loop and making it looks so easy thanks !
This is the best explanation ive had
thanks for making this easy to understand.
in love! finally i understand while !!
Thank you for the clear explanation 🤩!!
Great
My prof said that the "not" is rarely seen in coding then he used it, WOW!!!
You are doing a great work
This is pretty fun, thanks!
thanks this was beautifully explained.
nice video❤
How can it be so easy!!! thanks a lot!
Thank you for making it simple.
good work bro!
2-hour lecture of the professor yapping vs a 6-minute video to learn so much more
thanks a lot bro im starting python and this helps
nice video, thanks Bro!!!
you saved some lives here
Thank you! You're a great teacher!
Thanks man!! It's a good explanation
hello sir, why my computer when running infinite loop such like your video in 2:14 caused my mac so hot (%CPU about 300%)? i'm using python from conda, vs code, and macos ventura
while loop is infinite and when it runs it puts a load on your pc sometimes if you don't stop it your code editor might also crash
@@abdevil2330 but some of my other machine, let say intel mac doesnt get so hot, but the performance also slower than this silicon mac, i dont know if the configuration is the problem or what. let say the other machine (my android, running python with pydroid3) also doesnt get hot neither crash.
Big thank you for your excellent video!
Brocode is really a big bro❤
that explanation was so good I transcribed some of it for my notes verbatim!
Super
Thank you very much for doing this.
thank u so much this video explained clear but can u help me explain why when i'm writing nested while not working ? please can u help please
thanks to you i undrstand this while loop thank you so much
enter = input("Would you like to say your favourite food? (y/n): ")
while enter == "y":
food = input("Enter your favourite food: ")
enter = input("Would you like to say another favourite food? (y/n): ")
print("Thanks for stopping by!")
Such a good video!! Thank you so much for this tutorial it helped a lot.