+ 1

I dont really get it

the return from function.

27th Jun 2017, 11:01 AM
stephen haokip
stephen haokip - avatar
1 Answer
+ 1
I'll tell about an example before coming to real usage. it'll help you better let's think about a function called isMammall() this little function has some code which can tell if any animal name you provide is a mammal or not. (there isn't any such function. but just imagine it for the sake of it) now, if I want to know if 'Human' is a mammal or not, I'll use the function as below. isMammal(Human); but how will I ever know what the answer is? You can always put an output print code inside the function isMammal(). But it may not always be the case that you want to print if an animal is a mammal or not. for solving this problem, we use return statement. Imagine that this function return true if the animal is a mammal and false if it isn't. then I'll use it like boolean isHumanMammal = isMammal(Human); now we have the value true in the variable isHumanMammal. (because humans are mammal) we can use this variable, or compare it and do other functions. now telling the real usage. there is a function which delete entries from a database. it returns the number of entries deleted as an integer. This way, we can notify the user how many entries we're deleted. also, return are used in many functions to tell if the function code was successfully carried out or not. This helps the programmer in debugging. You'll learn more deeply after you start practicing making small applications. thx! Good luck coding!
27th Jun 2017, 12:46 PM
Snehit Sah
Snehit Sah - avatar