1 00:00:01,580 --> 00:00:03,690 Hiding the strings of the heart from the smarter. 2 00:00:03,740 --> 00:00:07,880 Welcome to the next video of this section of functions in Cortland. 3 00:00:07,880 --> 00:00:13,270 Now in this video we will learn about how to use functions as expressions. 4 00:00:13,280 --> 00:00:21,290 Now in the previous section we already learned how to use an expression and also an expression so you 5 00:00:21,290 --> 00:00:24,130 must be doing Vardis expressions stands for. 6 00:00:24,350 --> 00:00:28,330 If you have not followed my previous videos then please check those out now. 7 00:00:28,400 --> 00:00:34,940 The expression in here is of quarterly returns something so we can make a function as a whole to return 8 00:00:35,000 --> 00:00:36,090 something. 9 00:00:36,110 --> 00:00:39,160 So let me show you inside the intelligent ID Vought. 10 00:00:39,170 --> 00:00:41,140 I am actually talking about. 11 00:00:41,250 --> 00:00:48,100 I suppose if I define a function like C-Max to find the largest number of the given numbers. 12 00:00:48,130 --> 00:00:57,520 Right so here let us pass stupid meters as a as in And again B as in right now. 13 00:00:57,530 --> 00:01:00,220 Inside this I will simply write IF condition. 14 00:01:00,290 --> 00:01:10,100 If C is greater than B then simply put it on a is simply written b. 15 00:01:10,110 --> 00:01:13,650 And now here I will simply give the return type as in. 16 00:01:14,310 --> 00:01:19,740 So this function simply returns the greater number of these two parameters and B. 17 00:01:19,740 --> 00:01:26,360 Now from inside the main method I will simply call Max let's see forward and let's say 6. 18 00:01:26,370 --> 00:01:32,920 Now here I will simply assign it to that large value equal to this function. 19 00:01:33,270 --> 00:01:37,680 And now I was simply putting the largest value. 20 00:01:37,780 --> 00:01:39,210 So this completes our code. 21 00:01:39,250 --> 00:01:42,300 So there just not the code. 22 00:01:42,370 --> 00:01:47,630 So here we get to the agreed that number is actually 6 right now the question arises. 23 00:01:47,650 --> 00:01:50,560 Can we optimize this function that is. 24 00:01:50,590 --> 00:01:55,560 Can we express this function in less number of corde not Cartland compared to Java. 25 00:01:55,600 --> 00:01:58,720 Is actually more expressive and more concise. 26 00:01:58,720 --> 00:02:01,930 So here comes the role of function as the expression. 27 00:02:02,140 --> 00:02:05,700 So we can optimize this order by simply let's see. 28 00:02:05,710 --> 00:02:08,360 Converting this function into expression. 29 00:02:08,470 --> 00:02:15,210 So here what they will do is simply give equal to sign and then simply write the if condition. 30 00:02:15,550 --> 00:02:25,600 Let's see if it is greater than the then simply return a as return b like this. 31 00:02:25,960 --> 00:02:29,860 And now let us remove these lines of code on the side. 32 00:02:29,980 --> 00:02:34,670 So here I've simply optimized my code into just a single statement. 33 00:02:34,780 --> 00:02:36,550 So here this function. 34 00:02:36,550 --> 00:02:42,520 This is a function definition which is actually acting as a expression. 35 00:02:42,580 --> 00:02:49,350 So this expression is simply returning some value if is greater than B then simply return a is returned 36 00:02:49,380 --> 00:02:49,990 be. 37 00:02:50,290 --> 00:02:53,060 So it is not in the code and let's see what happens. 38 00:02:54,160 --> 00:02:57,860 So in outward console we get the greater number is six. 39 00:02:57,880 --> 00:03:00,760 So this was all about the functions as expression. 40 00:03:00,850 --> 00:03:07,570 Now suppose you have multiple statements in case of if clause and also in case of as close so far down 41 00:03:07,570 --> 00:03:11,750 you can also converted into a body like this. 42 00:03:11,820 --> 00:03:12,370 Right. 43 00:03:12,520 --> 00:03:13,650 Even in as far. 44 00:03:13,690 --> 00:03:15,720 Convert it into a body. 45 00:03:15,820 --> 00:03:17,940 So all you can say it is a block. 46 00:03:18,040 --> 00:03:21,500 So here what they will do is I will simply write some statement. 47 00:03:21,700 --> 00:03:26,260 I will simply put it at the bottom and now here letters. 48 00:03:26,350 --> 00:03:35,360 Right few more statements such as print is print is greater is print B is greater right. 49 00:03:36,940 --> 00:03:41,470 So here what I have is this function is again acting as an expression. 50 00:03:41,470 --> 00:03:43,710 Now here what they have is equally true. 51 00:03:43,770 --> 00:03:51,160 If is better than B then simply print this statement and then simply return this value is simply the 52 00:03:51,220 --> 00:03:53,890 statement as they returned this value right. 53 00:03:54,100 --> 00:03:58,050 No vorticity you right at the end of the block is actually returned. 54 00:03:58,220 --> 00:04:00,130 And now suppose after a. 55 00:04:00,190 --> 00:04:01,670 Suppose if I write here. 56 00:04:01,780 --> 00:04:02,820 67. 57 00:04:02,830 --> 00:04:07,210 So this sixty seven will be returned instead of the right. 58 00:04:07,240 --> 00:04:12,100 So always remember this and this is loaded and so always remember. 59 00:04:12,130 --> 00:04:15,760 Inside the code block what do you write at the end of the block. 60 00:04:15,820 --> 00:04:17,190 Will always be returned. 61 00:04:17,410 --> 00:04:22,280 So here it doesn't remove it and now there goes the code. 62 00:04:22,340 --> 00:04:27,010 So in the output we get 6 is greater the greater number is 6. 63 00:04:27,010 --> 00:04:33,720 So 6 is greater is actually being printed here and greater number 6 is actually being printed here. 64 00:04:33,890 --> 00:04:36,140 Now let's try something different. 65 00:04:36,190 --> 00:04:40,430 As said the statement present at the end is always return. 66 00:04:40,450 --> 00:04:42,190 So let us try something different. 67 00:04:42,370 --> 00:04:43,070 Let's see. 68 00:04:43,180 --> 00:04:45,370 Let us use ninety eight here. 69 00:04:45,550 --> 00:04:47,120 So instead of returning B. 70 00:04:47,170 --> 00:04:51,100 Now ninety eight will be returned because it is present at the bottom. 71 00:04:51,400 --> 00:04:58,910 And now let us append Ellen here and also Ellen here and now let us the chord. 72 00:04:58,950 --> 00:05:02,440 So in the output we get the greater number is ninety eight. 73 00:05:02,480 --> 00:05:08,620 So this simply shows that there are data that is actually present at the end is always returned right. 74 00:05:08,740 --> 00:05:11,760 And now this B is actually acting as redundant. 75 00:05:11,810 --> 00:05:18,560 Very well resonant here so it doesn't move this 98 and then run the cold and then get back to our original 76 00:05:18,650 --> 00:05:20,180 output here. 77 00:05:21,060 --> 00:05:22,250 So here we go. 78 00:05:22,260 --> 00:05:25,780 So this was all about the functions as expressions. 79 00:05:26,100 --> 00:05:30,360 So you can convert any function as expression in case of Cartland. 80 00:05:30,360 --> 00:05:34,530 Unlike Java where you have to use the primitive way of calling. 81 00:05:34,530 --> 00:05:36,720 So this was all about this video. 82 00:05:36,720 --> 00:05:38,540 Thanks for watching and have a good day.