Hello, in this video, we are going to look at the control statement that you can use when looking at loops. So there's two control segments. There's the break statement and the continue statement. So let's cover the break statement. First. These are used within loops, they can be used within the for loop Do you want to or the do while loop, it doesn't actually matter, I want to keep it simple.
Get rid of all the loops kolaks that the usage is exactly the same in each one here to that we don't make it out. So run it just to make sure that you know what others do. And just to keep it simple code prints zero to nine who started zero, and its wall is less than 10. Not while I use less than or equal to 10. So the break thing what that does is it breaks the loop so it stops the loop from work. If I do great here.
Let's see what we get. So princess zero. So what happens is it goes through here and even It even moaned about this he says, dead code and the reason is dead code is because it will break at the end of the first pass. So, it declares our AI at zero while I just in time which it is i plus plus at the end of each pass, so it prints out all which is zero don't break. So basically exits the for loop, probably want to use exactly like if you might have some sort of condition like if, if I equals eight, then you might do a break. Break.
It does break like so. So it prints zero to eight, but it doesn't print the final value. So that's what break is the continue statement. What that does is it just skips the current path in the loop. And it continues with Dean Next pass. And if I duplicate this, now we'll actually comment this out as well, like so.
So instead, what we're going to do is let's see if we change this to five. And if I change this to continue instead, as you can see it has 012345678, we have the end of the loop, sorry, because it's at the end of the loop, it's going to go to the next iteration and it's a pretty before the print line. As exists skip five, so 0123 and four, then always five, it's a if i equal five, which it does, then continue so that means skip the rest of the path. Go back to the start, but before it is actually technically ended the past increments. So oiss six goes Here again, is our equal to six No. So it printed out 778 and nine.
And that's it for control statements. Those are the two control statements in Java and pretty much every other coding language. If you have any questions about their use cases, feel free to reach out and unusual. I look forward to seeing you in the next awesome Java video.