Welcome in his lecture, I'm going to talk about the labeled break statement again, but this time I'm
going to use it to terminate from a switch statement.
OK.
It's a lot before you can use a break statement to terminate the switch statement.
But a which statement is inside of a loop, will it terminate from the loop or from the switch is unclear.
Right.
So by using a label statement, you can Talgo which statement you actually want to terminate.
All right.
Without further ado, let's take a look at an example.
You know, normally the user queries the word find that program and the matched words get printed,
right.
However, now the business people have changed the requirements again.
Now they want a filter, they macharia.
So when the user queries the system, the correct words will go through a filter.
If one of the queries works is in the filter, then it won't be searched for.
So the filter adverts won't appear in the search results.
OK.
Here, the user searches for the again and the Antwerp's, but the Antwoord is an unwanted part since
it's in the filter so the program won't search for it, it will only search for the keywords.
Now, let's take a look at how to add this new feature into the word finder program.
I opened the previous program again.
The customer has said that the filter will be static for now.
So I think that I can filter the unwanted words using a switch statement.
Now, I'm going to type a switch statement here to filter the query words like this.
OK, now I'm going to typed unwanted words in a case closed like this case.
And or the OK.
So whenever the corporate world matches to the works in this case, close, this case clause will be
excluded.
OK.
I've used a switch statement instead of a statement here.
Do you wonder why I did so?
Because I like the conciseness of switch statement.
I think that's more readable.
I showed you this before.
Anyway, your inside, I'm going to break from it, let's see what happens when I do this.
Let's query the program using an unwanted word now.
Again, and lazy as you can see, it finds all the words I've typed, but it also finds at Princeton
wants towards the Antwoord.
That's because this break here breaks from the switch.
Then it continues and executes these statements.
So if nothing has changed here for now to fix this, I can add the labeled brake statement to Talgo
that I don't want to break just from the switch.
I also want a break from the NSA.
OK, let's do that now.
Now, I'm going to add another label just before the nested loop here, so these labels to nested loop
with a search label now.
Now, let's at this label next to the break here so that it will break out of the nested instead of
the switch.
Now, let's query the program using an unwanted word again.
Cool, now it filters out the unwanted words and the searches and prints for the wanted word since that
Dritz.
Let me show you the difference between an unlabelled break with a label, one A.
So when you use an unlabeled break inside a switch like this, it breaks out of the switch, then it
continues executing the rest of the statements right after the switch statement.
Is because God thinks that you want a break from the sewage.
However, use a label to inside a switch breaks out of the loop, instead they'd continues executing
the rest of the code after the next loop.
All right.
That's all for now.
So in summary, you can use a labeled break to quit from the loop instead of a switch.
OK, thank you for you.
See in the next picture.
Oh, I.