Welcome in his lecture, I'm going to talk about what is the Gotha statement and how to use it.
By the way, go to is rarely used, so this lecture is completely optional, you can skip it if you
want.
OK, now let me talk about the go to statement briefly, first go to statement allows us to jump to
a label within the same function you saw that you can use a break or a continuous statement to jump
to a label.
Right.
However, they only work by use them inside the for statement or in a switch statement, on the other
hand, go to statement doesn't have that restriction since the label belongs to a function.
So it can be used from almost anywhere as long as you are inside the same function.
OK.
OK, let's take a look at an example to see how it works.
Now, I'm going to create the loop without using the false statement, and instead I'm going to use
I go to statement, this will show you how the goal, the statement works.
OK, OK, let's be an interval now.
Israel will store the current look index just like a four Staples index variable.
OK.
And after that, I'm going to declare a label name loop like this.
Then just below that, I'm going to type and if statement like this.
If I is less than three.
OK, just like an ordinary loop is artificial loop first checks the condition and then decides whether
to continue the loop or not.
You know, I'm just saying that if the next variable is less than three, then keep looping.
Inside, I'm going to increase the index variable by one.
So that's when the airable becomes greater.
That's right.
The loop will be terminated.
OK.
Only one thing is missing right now, how to make it behave like a real loop.
To do that, I'm going to use a go to statement to jump back to the loop labeled a ball like this.
This statement will jump to this loop label.
And then the statements right after Leupp label will be repeated again and again, so this works exactly
like a real loop, right?
Actually, real loops also work in this way.
All right, now, let's also bring the message that the council like this.
So that I can see whether it actually loops or not.
Also, I'm going to print another message when the loop ends like this.
All right, now the program is ready.
Let's run it.
As you can see, it loops three times, then it terminates from the loop, then it prints the -- message
here.
I've literally imitated a loop is a negative statement.
This was just for demonstrating.
You have the go to statement facts, but I'm not advising you to create loops like this.
Of course, instead of a go to statement, I prefer using a false statement, of course, and then you
need to jump, use the labels, break and continue statements.
Use the Gotha statement only when it really simplifies your code.
OK?
Actually, it's a very simple statement, and I think it's self-explanatory.
However, let me show you again visually.
You just declare a label to use and go to statement to jump to that label, and that's it.
However, you can't use the go to statement from anywhere.
Let me show you, there are a few rules.
The first rule is that code doesn't allow you to jump to a label after new wearables have been introduced.
Let's take a look at an example to see what I mean by that.
Airable is declared here right now.
I'm going to jump to the loop label just before this declaration like this.
Gore says that you can't jump after the declaration of the IRA, but think about it, what would happen
if you could jump to the label without declaring the IRA?
Well, in that case, the IRA wouldn't have been declared and it wouldn't be exist.
Then the program would jump here and it wouldn't be able to find the IRA able if this was allowed.
Think about how many bugs this will create.
So go to Engo is not like the Agota statement of the historic programming languages, they allow you
to jump anywhere in your statement is more restricted variation compared to those historic languages.
Gore team has restricted it because Gotha can be a very dangerous statement.
To learn more about the dangers of an unrestricted go to statement, please read the articles that are
added to the resources.
Although it's dangerous when used correctly and moderately, sometimes it may really simplify your code,
but it should be the last resort.
OK.
Perfect.
Now, you've completed all the steps, you learned a lot of knowledge in Congress, this was the last
step of the part three and you made it again.
That's great.
Now you have to control the flow of your programs.
Thank you for watching.
So far, seeing the next part of my.