Hey, guys, what's up?
So today we are going to learn a new thing, which is called switch case.
OK, so this is same as your finals.
So, for example, if I for example, if my question is if the character is M. Brent.
Monday.
If the given character is the then print Tuesday.
OK, so with the help of offenders, we can solve it very easily.
What we will do, we will take a character, C.H..
We will take input and then we will check if passage equals M.
Then we can print C out whatever they want to print.
And see if we can check.
If my character is D, then I can print something like Tuesday as I can print like invalid character.
OK.
So we can solve this problem easily with the help of if and save.
And as.
But we have to solve this problem with the help of such case.
So such case works very similar to offenders.
So what we will do is.
We will take a character, C.H..
We will take input, sit in S.H..
Now.
We will use a keyword switch.
C.H..
And then here I will be, I think is so case S.H. equals M.
So if this is the condition, what I will do, I will see you out Monday.
See you out Monday.
Break.
And if my character is thie, then what they know what I will do.
I will seek out.
Tuesday.
And then break.
Similarly, let's see if my current bet is S then C out.
Sandy.
Break.
OK.
And let's see if character is neither M nor B. not as so deformed.
So they default.
See out.
Invalid corrected.
Break.
And here, my switch will finish.
OK, so this is the opening of search.
This is ending.
So here there is no need to write break.
And via I am writing break here.
Because if the given characters am, I will do my book and then break.
OK.
In case of if and if they were automatically broken.
OK.
So they were automatically broken with the help of these opening and closing.
So here we have to break it.
But I think this.
Break.
And big.
And I'm telling you, there is no need to write break here.
Why?
Because by writing brick here I will reach.
At this point.
Similarly, if this be extreme, when will it be executed?
I will reach here and similarly, when this big statement will be executed, I will reach here.
But in case of default, default is already the last line.
Default will be written only at the last.
OK.
So after this.
So after writing the default statement, the next line is automatically this ending record.
So there is no need to write.
Break it.
OK, so let us implemented.
Switch Nazi BP.
So I am taking a variable S.H. user will give us the value of variable S.H..
And now I'm using switch.
So switch S.H..
And now I will be having cases.
So case.
My character is.
So I have to print see out Monday.
And then we have to right break.
So break is very important, Don, for a gator, too, right?
OK, so it is very important.
Now, the next case is my character is.
So in this case, I have to print QST so C out.
Tuesday.
So you can you can write multiple lines.
For example, you can write here also.
Let's let Soucy out.
Hello.
Okay, so there is no compulsion that we have to write.
We can write only one line.
No, we can do anything that we want to do.
And when your work is over at the end.
Right.
Break.
OK.
So let's see.
Case when my character is as.
So then I have to see you out.
Let's see.
Sunday.
So as I told you, we can do anything.
For example, suppose if I am having a very Billye, I can also incremented value here.
We can do anything.
OK, so suppose there's a variable, I guess so, let's make it.
Let's say and die equals when.
OK.
And at the end, we can write default in case of a Fenner's.
The last line.
The last we used to write this is.
So here we will write default.
So default default means when all that conditions are default, then default.
The statement will be executed to seek out
invalid character.
OK.
So here you.
There is no need to write big.
OK, you can write it.
My day is no compulsion.
OK, so I am not writing.
So this is all that we have to do.
Okay, so let's run our program.
Let's hear that.
In four days.
And so Monday's getting printer.
Let's say the in four days.
So Tuesday and hello is getting printed.
And similarly, let's see my characters as so Sun is getting printed and also the value of I is incremented
by one.
So you can bring I hear you out.
I.
Knowledge tested again for S.
So if my character is as Sandy and too is getting Prenter the way Levi is incremented by two.
And now let us give an invalid character to W..
So output is invalid.
Character.
So how it is working?
Just like a friend is.
For example, let's say my input is DeBlois.
So I will check is DeBlois it to him?
No.
Is WC history?
No.
As no.
So all these two conditions are false.
Then I will reach and the false statement invalid.
Correct.
So our word will be invalid character.
Let's say my input is.
So let's hear my input is.
So first of all, I will check is Amoco's him?
Yes, the condition is true.
You will print Monday and then you will break.
So by writing a statement, you will reach at the end.
OK, so now it probably be Monday.
Similarly, let's say you give input B..
So, first of all, you will check this condition is Emma Christie.
No.
Then Estee Acquisti.
Yet the condition is true.
You will print Tuesday.
Then you will print yellow and then brick by writing brief statement.
You will reach and.
And similarly, for as.
OK.
So the floor is very similar to a finals.
Now, what would happen if I remove Blake's statement?
Let's see.
So if I want to remove so if I removed this break.
So what will happen?
I believe we should not do this.
But if I am doing this, then what will happen?
So if my input is M Monday's getting Brendan.
So Monday, Monday is getting printed.
Then this brief statement is executed.
So for them, it is working fine.
Let us best for as.
So Sunday and do so s is also working fine.
OK.
Now, let us test for our default and character, let's say a so invalid character default is also working
fine.
Now we will see what will happen if I give B as input.
So give us input Tuesday, hello, Sunday, and do so Tuesday, hello, Sunday, and do so what will
happen if your home Blake's treatment?
So this is my big statement that I have removed.
So what will happen?
He has input.
They will check a Istiklal with him.
No.
Then he will check is the to be.
Yes.
So what?
What it will do.
It will print Tuesday.
So Tuesday will get the printer.
Then it will come to next line.
It will print.
Hello.
So Hallowell get printed now.
Brick is not there.
If Brick was there, my output will be too strong.
Hello.
And I will reach at this point since break is not there.
I will reach this line.
Sunday.
I guess this condition will not be checked.
I will likely reach here.
I will print Sunday.
The value of I is incremented by one.
Then CEO day two is getting printed and here I got breeks treatment.
Okay.
Here I got a brief statement.
Then it will break.
OK.
So if Big Street Bank was not there, if this big -- right is also removed, I will come down.
I will print in relitigated.
But Anton.
OK, so that is the reason why using Brigg is important.
OK.
So there are use cases also of note writing.
Rick, let me show you.
So first, they're disconnected.
Now what I want.
Let me show you the benefit.
For example, case, small limb.
So for small lamb, virtual game output, my output should be Monday also.
OK.
So my Bush would be Monday.
So what what I will do, I will leave it blank.
Just it.
Now, give the value small them as input.
So small them.
Boom.
Monday is getting printed.
And this is war and this was our requirement.
So how it happens?
So how it works?
You'll give small as an input M equals M.
You have not eaten anything.
Also, there is no breeks treatment.
So this condition will not be djent.
I will reach here Monday blueprinted and then base treatment will be executer and you will reach and
off switch.
OK.
So if you want to ride this same in a friend is what you could have done if my character.
It was it was Capital M or my character Aequitas.
It was small M, then you will print C out Monday.
And this is the closing.
OK, so this closing and this break, they are similar.
OK, so this all can be used in this way.
By not writing brick or by not writing any statement.
Okay, so let's see some more examples.
So I am doing some changes to my discordantly, so I am going to move angered.
Now for em, let's say this came one day.
No letters and a condition for small D. also.
So case I have small D.
And then in that case, where do you want to do is I want to bring.
And that's say Tuesday.
So see out Tuesday.
Blake.
And now under those three move.
This hello.
Also, let us remove this big statement.
So, OK, so this is all.
OK, let's change this also.
Instead of writing in inhalator character.
And the M or M or the O or small T.
OK, so let's see.
You have to tell me what will be my output.
We don't need you also.
So I am removing it.
So let's see.
So for small him virtual room output, my output should be Monday and then bakes, children will be
executed, some output should be Monday.
OK.
Someone is getting printed.
Correct.
For Capital M. Also, Margaret will be Monday.
No doubt.
OK, so now see the interesting part.
Capital City.
So if my input is Capital D.
So in for Capital D.
What should be my output?
Tuesday and Tuesday.
OK, so outproduced, who is Yanda is J.
And this was expected.
So you are giving these as input.
So first of all, we will check this condition false, this condition false, this condition.
I will print Tuesday.
Then I will not check this condition because there is no big statement.
So I will like lead each year.
I will bring it Tuesday and then I'll get based treatment.
So I will reach here.
OK, so this is how it is looking.
Now, let's see for small, do you also.
Smartie.
Tuesday.
OK.
Expected and now let us go in a little bit.
Let's see, eh?
So enter M.
Oh.
So this is their default statement.
There is no compulsion to write.
Default statement.
It is our choice.
Now, let us give invalided, connected.
Nothing will happen as expected.
Why?
Because first of all, this A will be checked with them, then with a capital M, then capital D. Then
small B, all therefore conditional false default is not there spiritual federal and returns zero will
be executed.
So nothing is getting printed.
OK.
So this is how switch case work.
So such case is very similar to offenders.
But I always prefer to use offenders because if as is much more simple than switch keys, there are
many chances of mistaken switching keys.
So I always prefer to use a friend as a comfort.
They will switch case.
You can use switch gears, but I always use a friend.
OK, so this is it for this video.
Thank you.