Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,270 --> 00:00:01,470
What is going on, guys?
2
00:00:01,510 --> 00:00:06,360
And welcome back to another video where we are going to talk about functions.
3
00:00:06,510 --> 00:00:13,860
So in this lesson, I would like to keep showing you how much these functions topic is not so scary.
4
00:00:14,250 --> 00:00:18,180
And I do this by simplifying things to the simplest level for you.
5
00:00:18,330 --> 00:00:22,080
Don't worry if we haven't seen this code for functions just yet.
6
00:00:22,410 --> 00:00:29,310
Trust me that these preparation is far from being less important than jumping straight to the code.
7
00:00:30,180 --> 00:00:33,120
So now let's make another brief analogy.
8
00:00:33,510 --> 00:00:35,130
Let's say that we have John.
9
00:00:35,550 --> 00:00:36,810
John is a function.
10
00:00:37,170 --> 00:00:43,980
He sits in his room and he knows that all he has to do whenever someone calls him is to receive three
11
00:00:43,980 --> 00:00:51,300
numbers, calculate the average and return to return the result to whoever call him.
12
00:00:51,590 --> 00:00:56,190
OK, so let's talk in more details about how John operates.
13
00:00:56,310 --> 00:01:04,770
So, first of all, it's very important to understand that that every function has a name and that this
14
00:01:04,770 --> 00:01:11,910
name should be unique because we want to be able to separate, to distinguish between all of these different
15
00:01:11,910 --> 00:01:16,320
functions that we may have, just like we've done it with variables.
16
00:01:16,470 --> 00:01:19,380
So we know, for example, the name of the function is John.
17
00:01:19,470 --> 00:01:24,600
And there also may be other functions like let's say we just call them.
18
00:01:24,670 --> 00:01:26,070
This way, Sara, Mike.
19
00:01:26,070 --> 00:01:27,540
And so on and so forth.
20
00:01:27,690 --> 00:01:34,980
We will also talk more about proper naming scene programming as we go into these section and as we go
21
00:01:34,980 --> 00:01:38,400
to the more advanced courses when we are going to discuss it.
22
00:01:38,490 --> 00:01:46,290
So once again, let's say that John is some guy with some specialty and he is inside of his room.
23
00:01:46,390 --> 00:01:49,890
It's John's room and John receives three numbers.
24
00:01:49,950 --> 00:01:57,540
So whenever we would like to come to John's room, John will await to receive from us three numbers.
25
00:01:57,810 --> 00:02:03,300
And these three numbers that John expects to receive are called parameters.
26
00:02:03,720 --> 00:02:08,640
We will say that every function may expect to get some parameters.
27
00:02:09,240 --> 00:02:14,580
The function may expect to receive one, two or even five parameters.
28
00:02:14,730 --> 00:02:20,310
That's usually not limited to some number of parameters that the function may expect to get.
29
00:02:20,460 --> 00:02:24,450
But usually functions are not being used with plenty of them.
30
00:02:24,630 --> 00:02:29,410
And also, the function may not expect to receive any parameters at all.
31
00:02:29,430 --> 00:02:29,820
Right.
32
00:02:29,850 --> 00:02:32,670
It may expect to receive zero parameters.
33
00:02:33,150 --> 00:02:35,340
That's all depends on the function itself.
34
00:02:35,460 --> 00:02:41,730
And to summarize, think of this step when the functional receives parameter says when these John guy
35
00:02:41,730 --> 00:02:47,370
stands at the entrance of his room expecting to receive the relevant parameters.
36
00:02:47,730 --> 00:02:51,990
And when you're going to use it some function, know that this function.
37
00:02:52,020 --> 00:03:00,120
This guy who stands at the front door expects to, first of all, obtain some parameters before it starts
38
00:03:00,240 --> 00:03:01,590
executing its code.
39
00:03:01,680 --> 00:03:09,300
So before John will start executing all of its code, all of its core, all of its war, its specialty
40
00:03:09,300 --> 00:03:18,300
of what it was created for, it, a ways to receive some parameters that may be useful for his execution
41
00:03:18,300 --> 00:03:19,170
of these code.
42
00:03:19,200 --> 00:03:19,550
OK.
43
00:03:19,740 --> 00:03:26,670
And once the function received its list of parameters, our function, our John Boy is going to close
44
00:03:26,670 --> 00:03:29,850
the door and start doing his thing.
45
00:03:29,970 --> 00:03:37,620
So his task, his thing may be to calculate the average grade or find the maximum or print something
46
00:03:37,620 --> 00:03:39,570
to the screen or anything else.
47
00:03:39,720 --> 00:03:45,150
And this task is accomplished by executing the commands of this function.
48
00:03:45,300 --> 00:03:51,480
So these different commands or far functions are called the functions body.
49
00:03:51,720 --> 00:03:58,470
And in the functions body, you may have usage of different local variables, which are just variables
50
00:03:58,470 --> 00:04:04,920
local to the specific space of the function, to the specific room that the function and security code.
51
00:04:04,950 --> 00:04:09,600
Now these local variables are just local to jawans room.
52
00:04:10,050 --> 00:04:14,510
We as an outsider as basically can not use these variables at all.
53
00:04:14,520 --> 00:04:14,880
Right.
54
00:04:15,090 --> 00:04:17,670
They are in a totally different room.
55
00:04:17,850 --> 00:04:25,050
And aside from local variables that may be created in this room, the function may have different assignment,
56
00:04:25,080 --> 00:04:28,230
mathematical input and output operations as well.
57
00:04:28,380 --> 00:04:34,650
And all of these things, all of these types of things, all of the core of the function is simply called
58
00:04:34,740 --> 00:04:36,000
the functions body.
59
00:04:36,180 --> 00:04:42,510
And that's basically one of the things that we are going to focus on in most of these section.
60
00:04:42,810 --> 00:04:49,710
So once again, we know that at the functions body, while the door was closed, all the desired code
61
00:04:49,710 --> 00:04:51,630
has been executed.
62
00:04:51,780 --> 00:04:57,580
And once the function is done executing its code, it may open the door and return something.
63
00:04:57,600 --> 00:04:59,850
Some results, some value to.
64
00:05:00,050 --> 00:05:01,080
Never called it.
65
00:05:01,200 --> 00:05:08,070
So suppose for this example, you've come to John when we know John is a function, we gave John three
66
00:05:08,070 --> 00:05:09,740
numbers of our grades.
67
00:05:09,990 --> 00:05:14,200
And then John executed the commands to calculate the average grade.
68
00:05:14,430 --> 00:05:18,720
Once he's finished, we expect the John or better say the function.
69
00:05:18,720 --> 00:05:19,080
Right.
70
00:05:19,410 --> 00:05:22,450
We'll open the door and return as a result.
71
00:05:22,470 --> 00:05:24,540
For example, the average grade itself.
72
00:05:24,570 --> 00:05:24,900
Right.
73
00:05:25,020 --> 00:05:26,700
We expect that, John.
74
00:05:26,760 --> 00:05:29,410
We'll give us the average grade at the end.
75
00:05:29,430 --> 00:05:29,700
Right.
76
00:05:29,770 --> 00:05:31,710
That he will return us.
77
00:05:31,770 --> 00:05:37,170
That the function will return as something some result of its execution.
78
00:05:37,260 --> 00:05:43,680
So we, as the callers who called the function, may expect the function to return as something.
79
00:05:43,950 --> 00:05:45,240
Once it's finished.
80
00:05:45,570 --> 00:05:48,280
So John may return something to us.
81
00:05:48,310 --> 00:05:51,000
And this something may be of different types.
82
00:05:51,300 --> 00:05:52,850
It may be of an integer, a.
83
00:05:53,180 --> 00:05:56,910
A floating point type, a character or any other type.
84
00:05:57,090 --> 00:05:59,460
And that's simply called the return type.
85
00:05:59,610 --> 00:06:00,660
The function type.
86
00:06:01,080 --> 00:06:07,890
So if in this case we know that a function should return the average grade, then we can say that this
87
00:06:07,890 --> 00:06:11,220
result is going to be of a floating point type.
88
00:06:11,910 --> 00:06:17,760
That's why we can say that the function type, the return type is going to be a floating point.
89
00:06:17,940 --> 00:06:24,330
And it's very important to know what type of value every function is expected to return.
90
00:06:24,390 --> 00:06:30,510
Before you even use it, because, I mean, you want to know what you should expect to get when the
91
00:06:30,510 --> 00:06:32,850
function has done, executing its commands.
92
00:06:33,270 --> 00:06:40,590
And now the door opens when when the door opens and the function returns you something you want to know,
93
00:06:40,830 --> 00:06:42,930
where should you store eating?
94
00:06:42,930 --> 00:06:44,580
What type of variable?
95
00:06:44,640 --> 00:06:44,940
Right.
96
00:06:45,030 --> 00:06:46,770
So I hope that's clear.
97
00:06:47,040 --> 00:06:53,130
And please know that the function may return some type of value, but it may also not return anything
98
00:06:53,130 --> 00:06:53,670
at all.
99
00:06:53,820 --> 00:06:56,700
It all depends on how we define our function.
100
00:06:56,760 --> 00:06:59,850
And we'll talk about this more.
101
00:07:00,540 --> 00:07:06,150
And you will understand much more in the following examples that we have in this section.
102
00:07:06,750 --> 00:07:09,030
So to summarize everything out.
103
00:07:09,150 --> 00:07:11,700
That's how you categorize a function.
104
00:07:11,730 --> 00:07:16,320
First of all, you understand that every function should have its own name.
105
00:07:16,530 --> 00:07:20,940
So then you can call this function by its name whenever you like.
106
00:07:21,140 --> 00:07:27,840
Then you specify for that function the list of parameters that the function is expected to receive.
107
00:07:28,470 --> 00:07:31,890
These parameters may be, of course, of different types.
108
00:07:32,010 --> 00:07:39,210
Also, you know that the function that John should do something, the function should have some commands
109
00:07:39,300 --> 00:07:40,590
associated with it.
110
00:07:40,920 --> 00:07:44,340
And these commands are called the functions body.
111
00:07:44,490 --> 00:07:50,250
That's exactly where we specify the content of the function and we will see more health.
112
00:07:50,250 --> 00:07:52,890
How how you really do it in code?
113
00:07:53,190 --> 00:07:56,280
In our examples and in our challenges.
114
00:07:56,400 --> 00:08:02,790
And lastly, for every function, you should specify the type of data it's expected to return.
115
00:08:02,940 --> 00:08:05,720
Will that be an integer, a floating point?
116
00:08:05,730 --> 00:08:08,640
Or maybe the function should not return anything at all.
117
00:08:09,060 --> 00:08:13,080
Just specify these information for your function.
118
00:08:13,200 --> 00:08:19,890
And with that being said, I hope that everything is clear and you understand the concept and the general
119
00:08:19,890 --> 00:08:22,810
structure of how functions look like.
120
00:08:22,950 --> 00:08:25,020
And that you are ready to move on.
121
00:08:25,200 --> 00:08:26,910
So thank you guys for watching.
122
00:08:26,940 --> 00:08:33,510
And in the next video, we are going to talk about how everything that we've learned in this video looks
123
00:08:33,510 --> 00:08:36,180
like in our programming language.
124
00:08:36,540 --> 00:08:37,980
So I'll see you there.
12041
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.