Return method | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Return method

In the given example, why is it used return? Why not just getting the sum of the two variables straight forward? I don’t get its usage :(

8th Apr 2019, 12:19 AM
Augusto
Augusto - avatar
2 Answers
+ 1
Can you show us the given example? The Q&A section does not link back to the lessons directly.
8th Apr 2019, 12:35 AM
Hatsy Rei
Hatsy Rei - avatar
+ 2
I believe that the example is part of a lesson. The answer to the question is the branch to the statement and the subsequent return is to illustrate the concept. To directly answer your question. The statement is branched to inorder to manipulate the data. The value of the variable s are assumed to have been changed prior to the execution of the statement in the branch. Once the new manipulation is done return is used to literally return execution to the proper point where the new values will be used. Having had prior experience with the concept eliminated confusion for myself, yet should not be the expected result. The lesson example should be made more verbose. I hope that this helps you. Feel free to msg me if you have need for a better explanation.
8th Apr 2019, 2:10 PM
Michael Williams
Michael Williams - avatar