0

What return statement does?what happens when we don't write return statement

4th Jul 2018, 4:52 AM
Bh G
Bh G - avatar
4 Answers
+ 5
when you have a return statement it means that when you call that function from main somthing will be returned back to it void just means that nothing will be returned to the function although theres a possibility you will print somthing to screen nothing is actually retuned to the calling function
4th Jul 2018, 6:03 AM
D_Stark
D_Stark - avatar
+ 1
Using pseudo code Sample 1: age = 14; CheckAge(age) function checkAge(num) { if(num < 18) { print("Too young"); } else { print("Old enough"); } } Sample 2: age = 14; text = CheckAge(age); function checkAge(num) { if(num < 18) { criteria = "Too young"; } else { criteria = "Old enough"; } return criteria; } print(info); If age was less than 18, info would get set to "Too young" etc.
4th Jul 2018, 5:01 AM
Andre Daniel
Andre Daniel - avatar
+ 1
Another example or return statement: value = multiplyTwice(4); function multiplyTwice(num) { return num*2; } value will be set to 8, because the function took the number (4), and returned a value based on a calculated value.
4th Jul 2018, 5:03 AM
Andre Daniel
Andre Daniel - avatar