Hiding the strings of the heart from the smarter.
Welcome to the next video of this section of functions in Cortland.
Now in this video we will learn about how to use functions as expressions.
Now in the previous section we already learned how to use an expression and also an expression so you
must be doing Vardis expressions stands for.
If you have not followed my previous videos then please check those out now.
The expression in here is of quarterly returns something so we can make a function as a whole to return
something.
So let me show you inside the intelligent ID Vought.
I am actually talking about.
I suppose if I define a function like C-Max to find the largest number of the given numbers.
Right so here let us pass stupid meters as a as in And again B as in right now.
Inside this I will simply write IF condition.
If C is greater than B then simply put it on a is simply written b.
And now here I will simply give the return type as in.
So this function simply returns the greater number of these two parameters and B.
Now from inside the main method I will simply call Max let's see forward and let's say 6.
Now here I will simply assign it to that large value equal to this function.
And now I was simply putting the largest value.
So this completes our code.
So there just not the code.
So here we get to the agreed that number is actually 6 right now the question arises.
Can we optimize this function that is.
Can we express this function in less number of corde not Cartland compared to Java.
Is actually more expressive and more concise.
So here comes the role of function as the expression.
So we can optimize this order by simply let's see.
Converting this function into expression.
So here what they will do is simply give equal to sign and then simply write the if condition.
Let's see if it is greater than the then simply return a as return b like this.
And now let us remove these lines of code on the side.
So here I've simply optimized my code into just a single statement.
So here this function.
This is a function definition which is actually acting as a expression.
So this expression is simply returning some value if is greater than B then simply return a is returned
be.
So it is not in the code and let's see what happens.
So in outward console we get the greater number is six.
So this was all about the functions as expression.
Now suppose you have multiple statements in case of if clause and also in case of as close so far down
you can also converted into a body like this.
Right.
Even in as far.
Convert it into a body.
So all you can say it is a block.
So here what they will do is I will simply write some statement.
I will simply put it at the bottom and now here letters.
Right few more statements such as print is print is greater is print B is greater right.
So here what I have is this function is again acting as an expression.
Now here what they have is equally true.
If is better than B then simply print this statement and then simply return this value is simply the
statement as they returned this value right.
No vorticity you right at the end of the block is actually returned.
And now suppose after a.
Suppose if I write here.
67.
So this sixty seven will be returned instead of the right.
So always remember this and this is loaded and so always remember.
Inside the code block what do you write at the end of the block.
Will always be returned.
So here it doesn't remove it and now there goes the code.
So in the output we get 6 is greater the greater number is 6.
So 6 is greater is actually being printed here and greater number 6 is actually being printed here.
Now let's try something different.
As said the statement present at the end is always return.
So let us try something different.
Let's see.
Let us use ninety eight here.
So instead of returning B.
Now ninety eight will be returned because it is present at the bottom.
And now let us append Ellen here and also Ellen here and now let us the chord.
So in the output we get the greater number is ninety eight.
So this simply shows that there are data that is actually present at the end is always returned right.
And now this B is actually acting as redundant.
Very well resonant here so it doesn't move this 98 and then run the cold and then get back to our original
output here.
So here we go.
So this was all about the functions as expressions.
So you can convert any function as expression in case of Cartland.
Unlike Java where you have to use the primitive way of calling.
So this was all about this video.
Thanks for watching and have a good day.