Welcome, intellectual.
I'm going to show you how fall through in a suit statement works first.
I'm going to show you a code snippet without follow through.
Then I'll refactor it into a version with false rule statements.
OK, let's get started.
Let's say that I want to create a program that will print the message depending on a number.
Let me show you.
Let's declare and travel like this.
When the ivory bill is greater than 100.
Then I'm going to print big positive number like this.
Or if the airable is less than a hundred and if it's a positive number, then I'm going to print positive,
no.
To reach this case, it has to go through the Ebola case first, so here I know that the number is less
than 100, right, because it already went through the Ebola case first.
Otherwise, I'm going to use a default case and I'll just print No.
Since it reaches this case, it means that the number is either equal to zero of its negative, for
example, I don't care about the negative numbers.
OK, OK, now let me execute this program.
It just brings back positive number.
It's because the airable is greater than 100.
Let me run this inside the code editor Ezer.
Here is the program, as you can see, it brings back positive No.
OK, now let's change the number to something less than handon like this.
OK, let's try to take a.
No, DePrince, just positive, no.
Is because it hits this case first eye is greater than handprint, so it yields false.
Then it tries this next case greater than zero.
This case yields true.
So it runs this case.
Novelis changed his number to zero.
OK, let's run it again.
This time, it just prints no, it's because it has tried all these cases.
But all of them were false, so it gave up and just executed this default glass because there were no
more options left.
As you can see in this program, I need to repeat this positive number and number values, right?
Actually, there's a better way I can use a follow through statement instead, I'm sure you.
I removed the duplicate strings now.
Now, I'm going to add a few full true statements at the end of each case, glossier.
First, I'm going to add a full true statement here.
Then I'm going to add another one here.
You'll see why that I'm doing this in a minute is, by the way, keep in mind that full true statement
should be the last statement inside a case, Claus's block.
OK.
OK, now on this program line by line.
Here is a line pointer when it moves on a line.
It means that deadline is going to be executed next.
OK, first he tries this case condition.
Since the airable is greater than 100, so it runs this case, it brings big.
Now it's about to execute the fall truth statement, what will happen when it executes it?
Let me tell you, this minute rounds to fall through statement, the program will direct the jump to
the next casis block.
So here it will jump to the left, empty that sprint without excluding the next case is condition.
Let's check it out.
As I said, it has jumped to the print and printed positive next to big.
So the full truth is used, it won't care about the next cases, condition, expression, and it will
directly execute its black.
Here, Volterra is safe because I know that handwrote is a positive number, so I don't need to check
the next casis condition, so I'll just let it fall through to it.
Now it's on the next fall, true statement again, it's going to drag the full truth to the default
chaos block as if it was never been there.
So it has printed no.
In the end, the output becomes a positive number without having to repeat the Sphinx.
As you've seen, instead of the brake statements, go has full truth statements in other languages,
there is no follow through statement.
Instead, they go to the next class automatically, that's why they need a brake statement, for example,
in JavaScript, in a switch statement, if you don't put a brake statements, it will execute the next
class automatically.
However, God doesn't need it because as I showed you before, go ask the brake statements to the end
of the each case clause automatically.
Let me show you this card in the codding Ed with different inputs.
Let's run this as it is, it brings back positive number.
All right, now let's change the number to 80, for example.
That's right now.
It brings positive number as expected.
This is because this case condition was true, so Gore has executed it then it has followed through
to the default clause.
Now, let's change the number to zero.
Let's run it now.
It just prints no.
This is because both cases were false, so it has only executed the default clause.
Actually, this was just a demonstration.
It doesn't mean that I would do this in a real life scenario, but it explains how awful through works.
Actually, a fall true statement is rarely used, but sometimes it may become useful, as in here.
All right, they're so.
Congrats.
Now you know how to use expressions within to each statement, and you also learned about the fall through
a statement.
Thank you for watching and see in the next lecture by my.