Welcome in its catting lecture, I'm going to show you a comparison between an IF statement and a switch
statement, so you'll clearly see which one to use and one.
Let's take a look.
In this program, I'm going to get a man's name from the common line, then I will print the season.
Let's first check that there are enough arguments, I'm expecting only one argument, so I'm going to
check for that like this if LAN is ARC's.
Not equal to two.
You've seen this a lot of times before, so I'm not going to explain it again.
All right.
Now let's assign the moms into the embeddable.
Umm, short declare that ARC's want.
OK, first, I'm going to check for the winter months, if is December or January.
Our February.
OK, then I'm going to print winter.
Prednisolone winter.
OK.
If demand is no interments, then let's check for Sprink bonds this time.
I'll see if I'm equals to March.
Or April.
Or May.
OK, now I'm going to print Sprink.
OK.
If the Mount is in a shopping mall mount either, then let's check for the summer months since that.
If, um, equals to June or July.
Our August.
OK, now I'm going to print summer.
OK, and lastly, let's check for the full moms'.
Passive equals to September.
Or October or November.
OK, the.
Then I'm going to print for.
OK, let's put on our branch here.
So if the user provides the wrong mom's name, I'm going to let the user know that it's a wrong mom
name.
F.A. printf person Q is not a mom's new line now I'm going to pass.
OK, this is a good behavior.
You should always display meaningful error messages like this.
OK.
OK, now let's try it.
First, let's call it directly with Antimonopoly.
It's brain implant, it detects that good.
Now, let's give it a winter months like this February.
Great, it says it's a winter months.
Now, let's give it a spring bounce, April.
Cool, now it says it's a spring once and lastly, let's try it with a wrong name like this.
Good, it displays their message.
OK, this car looks messy, right?
I don't know about you, but it's hard to read, at least for me now let me show you, how can I transform
this into a switch statement?
This will make it more readable.
Actually, the whole point of a switch statement in go is to make longer if statements more readable.
OK, now I'm going to type a short switch.
I'm going to declare the Amber Abel here first.
Then as its condition, I'm going to type the amber variable here.
All right.
Now, I'm going to duplicate these statements here.
I'm going to remove it right inside the switch statement.
Now, I'm going to select all the comparisons with Kamandi.
I don't need to let's remove the good going to select all the logical operators.
Let's convert them to commerce instead.
OK, good novelists select this as if branch's.
That's Makhdoom case Claus's instead.
This also changed this if here to a case class.
And this convert is our branch to our default case.
Now, let's convert is opening curly braces to Cullum's.
And lastly, let's remove the closing prices.
All right, Don.
That's right.
Let's run it a few times with different bombs go around mean that go February.
With April.
With June, with November.
Killed Celiac's.
And lastly, let's try it with a dummy mom's name again.
OK, it works.
Now, let's compare this switch to the if statement about.
I see a huge difference, this is what I was trying to tell you, so when you have an unreadable if
statement like this, try to change it into a switch statement instead.
Now, let's remove the if statement for good.
Right, that's all for now.
Thank you for watching.
See in the next picture by.