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
All right.
Let us just jump right into it.
So here we've got two functions.
This one returns a double when called.
This one returns a string, one called.
But for the sake of variety, let us add another function.
But this one, unlike these two, is not going to return a value.
You guessed it, it's going to be void.
And this void function is going to be called print area.
And this function is not only going to print the area, but the length and width that we're used to
produce that area.
So it's going to need to define three parameters double length, double width and double area.
And you might be wondering why is this function void and why are these returning values?
I will get to that in just a second.
But bear with me here.
We're just going to print.
Um, a rectangle with a length of.
Length.
And a width of width.
As an area of.
Whatever area that gets passed in.
Okay.
So why is this void and why is this returning a value?
And why is this returning a value?
Well, as I mentioned before, a function should only be performing a single task.
This one performs the task of calculating an area.
The function is already performing a computation.
It should not be the one to also handle the final result of that computation.
It should return the final result and let whoever is calling the function to deal with that result as
they see fit.
The explained area function is performing one task.
It takes in a language and based on the provided language, it compares it against three possible cases
and it explains the area in their preferred language.
This is a form of computation.
The function is already doing so much work, so it should not be the one to handle the final result.
It should simply return the result of that computation.
Whenever a function is performing a calculation or a computation of some sort.
It should not handle the final result.
It should just return the result and let whoever is calling the function to deal with that result as
they see fit.
But the function print area, its only task is to print the area.
It's not performing any calculations, it's not performing any computations.
So we cannot expect it to return any values.
That's why it remains void.
Void means the function does not return a value when called.
It's simply going to print a message depending on what gets passed in.
So what we're going to do is we're going to keep this simple.
We're only going to call explain area once.
We're only going to call calculate area once.
When we calculate an area for the following length and width, we're going to print that area using
the print area function.
The first value that we pass in is the length.
The second value that we pass in is the width, and the third value that we pass in is the area that
was produced from the length and the width.
And here we're just going to print the English explanation normally.
All right.
Putting breakpoints here, here and here.
Re visualizing the runtime.
So when you calculate an area for a length of 2.3 and a width of 3.6, you get a value of 8.28.
And inside of the print area function, we're simply printing that a rectangle with a length of 2.3
and a width of 3.6 has an area of 8.28.
If I just simply continue to the next breakpoint.
We're going to see that in our terminal.
String English explanation is going to equal whatever the explain area function computes based on the
language that was passed in.
So the language that was passed in is English.
We expect the explained area function to return the following text.
That's exactly what it does.
The English explanation variable stores, whatever the explain area function returns when we pass any
value of English.
And here we're just printing it.
All right.
The point I wanted to drive home was that when your function isn't performing any sort of computation
or calculation, if it doesn't need to return anything of significance, then it needs to be void.
Void means the function doesn't return anything when it performs its task.
So when you're just printing something, there is really nothing to return.
But when your function is performing some sort of calculation, some sort of computation that is needed
to produce a final value, then you need to return that value from the function and then let whoever
is calling the function to handle that value as they see fit.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.