Can we use two return values in a function? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Can we use two return values in a function?

If we need to check whether a number is even or odd. By using functions can we use two return statements by using if-else statement. Like: If(x==0) return(x); Else return (x);

4th Apr 2019, 2:21 PM
Shah Raashed
Shah Raashed - avatar
4 Answers
+ 1
Yes you can. It's like returning two different values, one at a time, based on a condition. But remember, you cannot return multiple values. For that you have to use other methods like aggregate data types or output parameters.
4th Apr 2019, 2:58 PM
Deepesh Choudhary
Deepesh Choudhary - avatar
+ 2
yes ,absolutely :)
4th Apr 2019, 2:33 PM
anjit pariyar
anjit pariyar - avatar
+ 1
anjit pariyar Thank you😊
5th Apr 2019, 8:53 AM
Shah Raashed
Shah Raashed - avatar
0
Deepesh Choudhary Thank you... Yes I know that I can not return multiple values.. but I m returning only one value.. if condition became true then it will return first value and if condition became false it will return the second value.. Thank you
5th Apr 2019, 8:53 AM
Shah Raashed
Shah Raashed - avatar