 Okay, so today we're going to take a look at go-to statements and go-to statements basically act like this. First we have to define a label, then we're going to have a go-to and then specify which label you want to go to. That's pretty much it. So basically what happens here is we have a label, we define a label up here and this go-to basically what it does is it transfers the execution back to this point in code. So for example if I see out, as you can see we've got an infinite loop and that is because, so basically what happens here is we begin this main function. This main function comes in here, it does this print statement, so it seeouts hello loop, then it comes down here and sees a go-to statement and says okay, so this go-to statement is telling me to go to the label, call the label and it comes up here. You can call the label anything you want. So if you want you can call it for example food and it pretty much does the same thing. The one reason you may want to use a go-to is to break out of nested for loops or nested loops in general. So for example if we wanted to break out of this loop, so let's say we do something, so let's say on this line here, this is a contrived example but basically let's say we define a new function, so we define a function boo or int boo and it takes int i and j and k and then it adds everything up and says, let's see, or should I say return i plus j plus k is equal to let's say five. So if we add i, j and k together, if it equals five we're going to return one, oops, we're going to return one, otherwise we're going to return zero, okay, so what we can do here is we can say boo and we're going to pass in i, j, then k and we're going to do something like if boo. So basically what would happen if I do like this, what's going to happen is it's going to break out of this loop, so it's going to break out of this nested loop. But it would not break out of this one or this one, so if you break out of this, it's still going to execute the remainder of the outer loop and if you break out of this loop it's going to execute the remainder of this loop. So basically what we have to do is instead of doing a break, so instead of doing a a break statement like this. What we would want to instead is we want to say go to exit loop. And then down here, just to make it a little more clear as to what I'm doing. Okay, so basically what we're doing here is exiting this for loop. So I want to exit this for loop and the end of this for loop is right down here. So we can define a new label and we can say exit loop. And this is going to be our exit loop label. So basically what's going to happen is when we, maybe I should make this a little smaller so you guys can see better. Okay, so basically what's going to happen here is when we execute this for loop, we're going to go from i0 to 0 to i is 99. Then we're going to do the same for j. I'm going to do the same for k. And here what I'm doing is basically I'm testing if foo, i, j and k, if they're equal to five, then we're returning one. Otherwise we're returning zero. So again, i plus j plus k is equal to five. If it is one, otherwise zero. So basically I'm doing something fairly simple here. And I'm using the go to to step out of this loop. And this is a lot cleaner than having to check the exit here and then checking the exit here and then or should I say checking the exit here here and then here to jump out of it. So I think this is the only example of using go to is that makes code cleaner than it would otherwise be. So let's actually print that out and see what happens. So okay, so basically what we got here is 9 is equal to zero, j is equal to zero, k is equal to zero. So as soon as k reaches five, so I guess this makes sense, right? So basically what we did here is we returned is i plus j plus k equal to five, returned one if it is and turned zero if it's not. Let's do something else. Let's do something like, okay, let's just change this value to 123 and see what happens. Okay, so let's see. So j is equal to 24 and then k is equal to 99 and then we get 123 from that. If you want to see what this would look like if we didn't use go to, we would have to do something like this. Okay, so as an example, if we were to remove this go to statement here and replace with a break, this code would not work anymore. So for example, if we do break I think I also have to remove this exit loop also. Okay, so the problem that's happening here is that we are looping through this nested for loop. And when we loop through this, when we call break, what this does is it breaks out of this for loop, but it does not break out of the nested for loop or should I say the outer for loop so this outer for loop continues running, even though we broke out of this one. So what we are doing is we're breaking out of this, but we're not breaking or should I say we're breaking out of this for loop, but we're not breaking out of this for loop or this for loop. So in order for you to be able to do that, the only way I think the only way I think you can break out of these three nested for loops is by setting a flag if you don't want to use a go to. So for example, you can say int, so we can say int bin zero. So if it's finished, I'm going to set it to let's see, I'm going to set it to one. And what we do here is we're going to break out of this. And then in this outer for loop what we're going to do is going to say if bin, then we're going to break as well. And then in the outer for loop again, if bin, break. So this isn't as clean. And because we didn't use a go to statement, and instead we relied on it's kind of like flag systems, we have fin variable, when this fin variable, when I'm happy with whatever I get, I set it to one, and then break out. And then I have to check this fin variable down here, I have to check this fin variable down here. And this is not clean whatsoever. This is like this code is a lot uglier than if I just simply used the go to. So for example, if I use a go to. So I can just do go to exit loop. I can delete this. I can delete this. Uncomment this. And as you can see, we get the same result. And we yeah, so we get the same result and the code is a lot cleaner with the go to than it is otherwise. But again, you will probably never have to use a go to like professionally. And even when you're writing algorithms or doing some competitive programming or doing some projects, even then you probably don't want to use go tos. The only use case for a go to is just jumping out of nested for loop. So like this, if you have a triple enested for loop quad triple least nested for loop or whatever, just use a go to to jump out of it instead of having to check on every nesting of the for loop if you should jump out or not. That's how you use go to statements in C++. And I will see you later.