Learn how Python's break statement exits a loop early. When a for loop hits a condition like `if i == 3`, break stops it immediately. The example prints 0, 1, 2 then exits instead of running the full range.
Chapters
Hello guys, welcome to Learn Python. So today we'll be going to learn about the break statement. Now let's start with the break statement and let's learn about that. So first of all, we're going to declare the for loop, that is for i in range, and then we're going to specify the range inside this bracket, and then we have to mention the colon for the syntax in Python. After that, we'll be going to use i, if i double equals to 3, and if we use the print statement, now we'll be going to display a message breaking out of the loop., and it will gonna display 0, 1, 2, and then breaking out of the loop because we have mentioned i double equals to 3. Now we'll be going to use the break statement over here so that it can break out of the loop once it shows 0, 1, 2. Now we'll be going to use the print function to print the output. So here we're gonna mention the print function, and after that we'll be going to run it to get our output by tapping on the run button.