Come back in this lesson we are going to talk about the operators in Objective C and for the most part
they would apply similarly to swithe.
So there are several different types of operators.
We have the AIs not the operators such as plus minus multiplication division so on and so forth.
If you have the relational operators like the ones that we saw in a conditional if a statesman equality
not equality larger or smaller larger than a quarter a smaller and equal.
Logical ones like the ones that we saw in again and he felt a statement and or not.
And we have the assignments one such as the one single equals sign plus equal sign minus equal sign
and so on and so forth.
For the most part these are quite simple.
A few of them do they feel like we might have to talk about them.
I would cover them in this lesson.
So let's move on to ex-coach scored.
I'm going to go ahead and close this project is start a new command line tool and this one I'm going
to call it all prayed for this project.
I'm so used to calling everything up because most often we do everything for us but I think here we
do some things for our project.
There are other command line tools and I don't want to type command line too it's just that such a long
name.
So in next quoting here I've got my diet and I'm going to get rid of all of that.
I'm going to reformat everything nice and tidy and clean.
And that's Lucar.
Some of these things.
So going back to my list the first one is the arithmetic operations and obviously plus minus what it
became and division they make all the sense.
These last three I need to speak about them really quickly.
So the first one is the percentage sign which is the remainder or what we call modulus modulus which
is the remainder of two values against each other.
So here's how it works I'm going to say in my mod it's going to be 12 modulus 5.
So if I print this volleyer now more is a percentage of my MOD.
What do you think I'm going to get.
What's the resort of 12.
Modulus 5.
Just to put that in context.
If this is the first time you're seeing it or if you don't remember it from.
I think most high schools at some point they cover this at least briefly or if you're new into programming
generally this is a sign of remainder it means you fight.
Divide the 12 way 5 foot is going to be remaining.
So if you divide twenty five five you get to five.
That is 10 12 minus 10 you will get two.
So that is the result of that.
And if I run this code are we we should get the exact same thing as well
so it says more is.
If I divide say 17 by 5 the result is going to be I think is again going to be true.
Yeah it is.
Let's see our example.
A very large number such as this one modulus 13 you know for better numbers such as two or three or
so on.
There are formulas for finding them but for numbers just 13 it's quite difficult to find it so I'm actually
going to go ahead and run this up on it tells me more this zero is actually this number can be divided
by 13 which is so surprising thing so when you go ahead and redo it.
So now we get 12 something to keep in mind which is very important is that whenever you get a modulus
of any number against any are divided essentially that metanoia this number to say 6 the results that
you can get are these 0 1 1 chance type 2 3 4 5.
So the results of this number are either zero.
It means this number perfectly divided by six or it is 1 or 2 or 4 8 to 5.
Let me simplify this number so we can understand why if this number was 13 13 modulus 6 would be 1 because
2 sixes are 12.
If this number was 14 14 much of the 6 would be two.
If this number was 15 50 miles the stakes would be three.
If it was 16 would before if he was 17 it would be five.
If it was 18 then it would then become 6 because it would divide one more time and would come back to
zero.
And that's what really helps us finding the remainder of a number.
For instance if we want to find out if a number is order even I will essentially divide them by two.
Let's go ahead and see that.
So I'm going to say in my art number is this number and then I'm going to say in odd divide resolved
is my number modulus 2 and then I'm going to say if the result is zero then it simply means it's even
an event.
Even so that's an odd number.
I get the remainder of the games too.
Depending on the result I decided that it is even.
Or you could add the else statement and decide what it is or what it is.
All right.
So that is how you would find for instance an even number.
Let me jump back to my presentation.
The next thing that we should talk about these two sides the increments and decrements.
So I have this number called my equals 23 for now.
What happens when I say my ends plus plus Let's go ahead and say and like my eans now is percentage
all and the value is my what do you think is going to happen.
I'm sure most of you would guess that it's going to increment it by a number.
So that's obviously the size of increments.
And certainly this one would be decrements and that's about that.
Another sign this is the science of assignment that we have talked about is I could simply say mine
is 23.
All I could say my wins plus equal three it means this is similar to saying this my ends so my end is
my eans plus three.
So this is a sign of get this add the 3 to it and put it back on itself just like what we had done earlier
on using my een is my enough plus three all the other operations they work similarly.
So this so to ask some puts it back inside.
This multiplies and puts it back inside.
This one divides them puts it back inside and this one finds the modulus and puts it back inside.
Let's do a little game.
So I have my integer 2 which is 23.
I'm going to say my one plus equal three then I'm going to say my eans are division equal to and then
I'm going to say my hands subtract equal 5.
Then I'm going to say my hands multiply equal 8 and then I'm going to say let's say I'm losing count
myself as to whether I'm doing my eans are modulus equal or 15.
So what do you think is the result of this fun.
Now luckily we don't have to guess.
Raise is a percentage of my end.
But before we go there I'm hoping that I'm doing the calculation right.
I'm going to say my unit is 23.
So 23 plus three that is 26 26 divided by two.
That is 13 13 minus 5.
That is 8 8 multiplied by 8.
That is 64 64 modulus 15 is for.
If I have done it right we should get to 4.
That's wrong.
I'm perfect result is for.
So that is another thing we need to read it to understand that we can use these operations of assignments
just think the very basic assignment.
But this assignment IEDs divides multiplies and so on and so forth.
So finally the last thing I want to talk about in this lesson is the priority of operators or the precedence
of operators.
Let me quickly demonstrate that by saying in my end is going to be 23 plus seven divided by seven modulus
seven.
What do you think is going to be the result of this.
Which ones do they calculate first or do they get to be calculated first.
And that's essentially the the the concept behind priority or precedence.
So if I go ahead and say enough is percentage in my hands.
Now we can see the result of it.
And the important thing to understand here is this there aren't there vehicles being collected.
Is that division or multiplication.
They get the first priority.
So essentially this happens first and then we get to do whatever is the result of that modulus by seven.
And that happens.
Second essentially.
And then the plus happens at last.
Now there are documents that one of them is the one I have shared with you guys with this lesson that
explains the specifics of the priorities.
It's kind of difficult to try and memorize all of them but what you want to make sure to know is that
multiplication and division they have a priority over plus and minus.
That's an important thing to remember.
So modification of the vision ahead of plus minus and then from there on if you were in a situation
that you needed to calculate this it makes all the sense that you actually put the practices behind
them or around them.
So for instance this very same piece of code.
It could actually be interpreted like this.
First get 23 at 7:53 then get seven modular set against seven and then divide them by each other which
would be a totally different result.
So to make sure that this kind of situation doesn't happen for you remember it always odds prothesis
or at least in these early days until you have a better understanding and a more confidence in what
you're doing exactly.
So the goal here was to first divide 7 by 7.
I would put them both within parties and then I would say well I want to make sure that this fall happens
again.
So within the practices and then the result of them will be on marginal us against 7.
So keep that in mind that it really helps that you know you use some sort of brackets and make sure
that you know exactly where you're going.
The last thing I want to show you is this are vus if his statements are extensively over the past few
lessons.
And there's another kind of statement that you could use which is my sense is fine if it does then and
it's like five else and it's like not five.
So this is essentially called a terror Nery if it's a stunt like this for Nery are conditional.
So it's basically a shorthand for saying if my eans is five then do something else do the other thing.
So in this case we say my end is it equal to five if it is true.
That's the sign of question mark.
Then do this call is a sign of the else part.
Do the other thing so just keep that in mind that sometimes you might see it in other people's code.
I don't personally use it almost ever but you might find it useful or you might decide to use it.
So that's of all the arts.
We covered a lot of elements in this in this lesson.
We went from operators to statesman's decremented instrumenting.
Understanding what is modulars.
I think we covered almost everything we needed.
And with that in mind let's move on to our next lesson.