How to Use "break" and "continue" in Python "while" Loops
Вставка
- Опубліковано 25 сер 2024
- You’ll walk through practical examples of how to use "break" and "continue" in Python when you're dealing with "while" loops. You'll debug the example code, so you'll get a clear sense of what’s happening behind the scenes.
Click here to learn more: realpython.com...
For those who are still confused, 'continue' doesn't really mean continue through the next steps in the loop, it means go back to the beginning of the loop . Why they used 'continue' to represent go back to the beginning is beyond me.
omg this is what i was searching for thanks for clarifying the whole things
yeah this actually makes so much more sense thank you so much
Some good clarification there. Thanks boss!
Thanks
Omg thxxxxxx bro
This was the most STRAIGHTFORWARD explanation. THANK YOU!
You really dont know how much thos tutorial has saved 12 hours of my life. thank you so much. Stay blessed wherever you are
This is best explanation I found on internet, thank you
clear as clear can be, thanks for your upload
thanks, before i did not understand this part of my course but now i can use it for my homework :)
Here's my definition: continue means skipping the rest of the code in the current iteration of the loop(ie invalid input), then immediately begins with the next iteration of the same Loop.
Thanks for this and more importantly thanks for bringing thonny to my attention, it's a game changer
FAR better explanation than my college professor. THANK YOU.
fr bro collage professors sucks
hello may i know how you show the visualisation of how the code work, 3:13-4:00
Wow !! Amazing Work !!! Easiest Explanation !!!
Thank you, great explanation!
This is more understandable example. Thanks 😃
I FREAKING LOVE YOU!!!!!! THANK YOU FOR THIS VIDEO!!!!
Hello, what is the name of this IDE you are using to develop in the Python language, I found it very interesting.
Vs better
Thank you so much madam
Thanks for the tutorial! I'm just curious, what editor/IDE is that?
It's a beginner-friendly Python IDE called "Thonny": realpython.com/python-thonny/
@@realpython Why didn't I know of it until now? Thanks!
@@realpython GOOD TOOL
Wow seems we are all stuck....
Thank you so much
perfect explanation
holy shit thank you this is actually so useful
You helped me a lot.Big thanks from me.
Thanks this helped a lot
Was anyone else forbidden to use break and continue in class projects as well?
nice and simple thank you!
great explanation! thank you!
Thanks you. This is so apt 👌
Thanks
Are you using sublime text?
Thank you!!
when you debugged the code line by line, which button did you press? I am wondering...
Thankyou ❤️
what is the IDE she used, by the way ,good tutorial
Which software are you runnign this on?
Seems really useful for debugging.
What kind of interpreter do you use?
Symple code:
import os
os.system('pause')
Can someone explain why there is a 0 before loop is finished if n is supposed to be greater then zero?
I made a simple guessing game with two questions, when you finish the first one you head to the second one,so I want that is the user fails the first question the whole game ends even the second question ends. Any ideas??
Hello, hello! Thanks for the great video! I am confused as to why "0" prints when we implement built in function continue wherein our while loop is set to n > 0. Can someone please explain? Thanks!
It prints 0, because it is during the condition of n=1. When n =1, it is >0, and on the next line it minus itself, so u get the result 0
In which platform you r executing this code?
Hello great video, could you write me what compiler do you use?
It looks like Thonny to me :) There's a cool feature where you can step into each step of the way (helps when debugging) as the program is executed if you click on the tiny insect instead of the play button.
IDE name?
I am trying to make it where once the nested if statement code runs, how do you jump right back into the while loop directly after the nested if statement? what can I do to make it jump out of the if statement once it’s done and continue the while loop? Using your code as an example, when n = 2 I want the if statement to execute, but then jump back into the while loop directly after the if statement and execute the print(n) which would result in “2” being printed. How can I achieve that?
In many programming languages, including Python, you can use the continue statement to skip the rest of the code inside a loop and move on to the next iteration of the loop. Here's an example to illustrate how you might use continue in the context of a while loop with a nested if statement:n = 0
while n < 5:
n += 1 # Increment n on each iteration
# Your nested if statement
if n == 2:
print("Executing nested if statement for n =", n)
# Any code you want to execute when n is 2
# ...
# Use continue to jump back to the while loop
continue
# Code after the if statement that will be executed for all values of n except 2
print(n) In this example, when n is equal to 2, the nested if statement is executed, and then the continue statement is encountered. This causes the loop to skip the remaining code inside the loop and move on to the next iteration of the while loop. For all other values of n, the print(n) statement after the if statement will be executed.
When you run this code, you'll see that "2" is printed as a result of the nested if statement, and then the loop continues, printing the values of n from 3 to 5
I see. So continue basically skips everything that was previously ran and restart the while loop with the new value.
name of software used to debug code?
Thonny
Why starts from 4
Cause we did 5 which is the initial n, minus 1. (N-1)
is the break under the if statement or the while loop?
continue does not work, its not even a command, its just red underlined
👍
1st rule of being coder
NEVER USE WHITE THEME
Thanks