Now, let us talk about the switch case, a statement which we've also talked about in the retail section.
So it's which case we've seen that already in jail.
It's very similar to the statement, but it's a little bit more extended.
So example to use that many with allegation.
And we're going to see also how we use it as a state machine with Adreno.
I mean, in virtually all the we would say case valuable.
And then here we use when when something do that when something you do that.
So here it's different.
Instead of saying case, we say switch.
And instead of when we use case, this is the difference between the HDL and the C C++.
OK, so we also use it for navigation.
Let's say that option one will show you some menu options.
Option two, let's say that valuable holds the option number.
So let's say you have a menu and every option has a number.
So when you press one, you're going to see options.
When you press two, you will see other options.
So the switch will check which option you have selected.
It will jump to the case and it will print on the screen what options you have in Central.
Let's say it's something like this when you call a central call for a company or something, maybe your
mobile company, all of those, you would be redirected to a voice central.
And they will tell you if you want to go to this menu, press one.
If you wanna go to this menu, Prestia, this can be programmed using switch.
No, it's also can be used for state machines.
And this is what I really care about the most in Adreno, because Audrina is a controller at a really
important to learn how to got state machines in there.
So you have no state machines.
You remember how you we have multiple states.
So the case is here.
All your states remember in the US, we had to define Dive's for states and stuff like that.
You already have the state, which is the case and you just enumerated with numbers.
OK, so here case one is the same as state one still is the same as state two.
And the variable is actually your state.
No.
OK, so let's say you are at switch and you see one.
We will jump to case one.
And here, let's say we say variable equals two so that when we go back to switch somehow maybe using
a loop, this state here will be two and be able to jump to case number two.
So the switch here will check its own variable, which is working in this case is check its value and
jump accordingly to the corresponding value.
So a vote equals one.
We jump, if I could, still with jumpier and so on and so forth.
So the case will execute.
And this same variable here, we can assign it to something else.
And as I said, we would be jumping to a different state.
Now, if we put this a switch in the void loop, it will continue executing forever.
Now, by taking a look at this, let's say that we put the switch inside the void loop of the ocarina
switch.
Well, let us see how it will execute, let's say valuable starts at values.
One will jumpier then it will say about equals do and it will do a break.
A break is a very important condition in order to say, okay, this case is over.
Okay, without that, you will have some issues as well.
So after every case, you have a break through.
Every case, you have a break.
So case code break, case.
Go to break.
OK, now this code right here will jump forever.
Why?
Because when you put this in a void loop and when valuable, it calls one rule jumpier, then we will
say valuable equals to.
And to break the break will break out of the switch.
Now, we broke out of this, which if this is inside the loop, we will go back to the beginning.
Now, what does valuably calls do we already assigned it to do so now?
Valuable equals to we will jump here, OK?
We are now in case, too, and we are assigning valuable to equal one.
OK, and then invaluable equals one.
We are going to execute some code and break, we break out of the switch.
We are inside an infinite loop.
We will jump back here and now what does valuable equal still.
Well we already assigned it to one.
We will jump back to one.
So this infinite loop will be jumping between these two states back and forth forever.
So this is the syntax.
This is how we rate state machines in Audrina Order.