They will discuss what the labels endure and how you can use them labels in combination with break and
continue statement, allow us to implement some kind of go to statement in Java.
But first of all, what is go to statement go to is a statement in different programming languages which
allows you to pass control of execution to any line in your code without any condition.
The jump two lines of code are usually identified by labels, but you have to consider it to be a bad
practice.
That's why in Java go to is reserved keyword but never used why it is considered to be a bad practice
because code which contains goto statements is less readable and it is harder to maintain.
Also, it is extremely hard to test code with code to statements.
But in Java we have labels.
We can use labels to break the loop marked with specific label or to continue another loop.
I would say that labels with break statements in Java is more structured form of goto statement.
You're already aware that breaks statement breaks only closed loop.
But in case you have multiple nested loops, how you can break the main loop labels will help you to
do this.
Let me show you how you can do this.
In this example, we have two loops here.
One loop is nested and we have two labels.
Label is any invalid went into fire followed by a colon.
We have loop one and loop two here.
Once we have label block of code, we can use labels as a target of a break and a continuous statement.
In this case, if counter in nested loop is less than three, we continue our execution from this block.
And this is just an example.
In real life, you can continue execution from any block you wish.
But in case our counter in nested loop is equal to three or more, we break our main loop.
That's one console output.
You can see that we managed to print.
I counter only once in console and the main loop was broken by the statement.
So now you know how to use labels.
Let's recap what we have learned in this section about loops we learn how to use for type of loops.
We also discussed how we can use nested loops, jam statements and labels.
Now, let's review your homework, recommend you read books, chapter about loops, and here's recording
exercises for you to practice.
What will review solution for these scoring exercises together?