Afrikaans
Akan
Albanian
Amharic
Arabic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
English
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
French
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Icelandic
Igbo
Indonesian
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranรฎ)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Persian
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Russian
Samoan
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Vietnamese
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
What is going on, guys?
And welcome back to another video where we are going to talk about functions.
So in this lesson, I would like to keep showing you how much these functions topic is not so scary.
And I do this by simplifying things to the simplest level for you.
Don't worry if we haven't seen this code for functions just yet.
Trust me that these preparation is far from being less important than jumping straight to the code.
So now let's make another brief analogy.
Let's say that we have John.
John is a function.
He sits in his room and he knows that all he has to do whenever someone calls him is to receive three
numbers, calculate the average and return to return the result to whoever call him.
OK, so let's talk in more details about how John operates.
So, first of all, it's very important to understand that that every function has a name and that this
name should be unique because we want to be able to separate, to distinguish between all of these different
functions that we may have, just like we've done it with variables.
So we know, for example, the name of the function is John.
And there also may be other functions like let's say we just call them.
This way, Sara, Mike.
And so on and so forth.
We will also talk more about proper naming scene programming as we go into these section and as we go
to the more advanced courses when we are going to discuss it.
So once again, let's say that John is some guy with some specialty and he is inside of his room.
It's John's room and John receives three numbers.
So whenever we would like to come to John's room, John will await to receive from us three numbers.
And these three numbers that John expects to receive are called parameters.
We will say that every function may expect to get some parameters.
The function may expect to receive one, two or even five parameters.
That's usually not limited to some number of parameters that the function may expect to get.
But usually functions are not being used with plenty of them.
And also, the function may not expect to receive any parameters at all.
Right.
It may expect to receive zero parameters.
That's all depends on the function itself.
And to summarize, think of this step when the functional receives parameter says when these John guy
stands at the entrance of his room expecting to receive the relevant parameters.
And when you're going to use it some function, know that this function.
This guy who stands at the front door expects to, first of all, obtain some parameters before it starts
executing its code.
So before John will start executing all of its code, all of its core, all of its war, its specialty
of what it was created for, it, a ways to receive some parameters that may be useful for his execution
of these code.
OK.
And once the function received its list of parameters, our function, our John Boy is going to close
the door and start doing his thing.
So his task, his thing may be to calculate the average grade or find the maximum or print something
to the screen or anything else.
And this task is accomplished by executing the commands of this function.
So these different commands or far functions are called the functions body.
And in the functions body, you may have usage of different local variables, which are just variables
local to the specific space of the function, to the specific room that the function and security code.
Now these local variables are just local to jawans room.
We as an outsider as basically can not use these variables at all.
Right.
They are in a totally different room.
And aside from local variables that may be created in this room, the function may have different assignment,
mathematical input and output operations as well.
And all of these things, all of these types of things, all of the core of the function is simply called
the functions body.
And that's basically one of the things that we are going to focus on in most of these section.
So once again, we know that at the functions body, while the door was closed, all the desired code
has been executed.
And once the function is done executing its code, it may open the door and return something.
Some results, some value to.
Never called it.
So suppose for this example, you've come to John when we know John is a function, we gave John three
numbers of our grades.
And then John executed the commands to calculate the average grade.
Once he's finished, we expect the John or better say the function.
Right.
We'll open the door and return as a result.
For example, the average grade itself.
Right.
We expect that, John.
We'll give us the average grade at the end.
Right.
That he will return us.
That the function will return as something some result of its execution.
So we, as the callers who called the function, may expect the function to return as something.
Once it's finished.
So John may return something to us.
And this something may be of different types.
It may be of an integer, a.
A floating point type, a character or any other type.
And that's simply called the return type.
The function type.
So if in this case we know that a function should return the average grade, then we can say that this
result is going to be of a floating point type.
That's why we can say that the function type, the return type is going to be a floating point.
And it's very important to know what type of value every function is expected to return.
Before you even use it, because, I mean, you want to know what you should expect to get when the
function has done, executing its commands.
And now the door opens when when the door opens and the function returns you something you want to know,
where should you store eating?
What type of variable?
Right.
So I hope that's clear.
And please know that the function may return some type of value, but it may also not return anything
at all.
It all depends on how we define our function.
And we'll talk about this more.
And you will understand much more in the following examples that we have in this section.
So to summarize everything out.
That's how you categorize a function.
First of all, you understand that every function should have its own name.
So then you can call this function by its name whenever you like.
Then you specify for that function the list of parameters that the function is expected to receive.
These parameters may be, of course, of different types.
Also, you know that the function that John should do something, the function should have some commands
associated with it.
And these commands are called the functions body.
That's exactly where we specify the content of the function and we will see more health.
How how you really do it in code?
In our examples and in our challenges.
And lastly, for every function, you should specify the type of data it's expected to return.
Will that be an integer, a floating point?
Or maybe the function should not return anything at all.
Just specify these information for your function.
And with that being said, I hope that everything is clear and you understand the concept and the general
structure of how functions look like.
And that you are ready to move on.
So thank you guys for watching.
And in the next video, we are going to talk about how everything that we've learned in this video looks
like in our programming language.
So I'll see you there.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.