Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

6
  • If the first term of the list is not the result, search through the rest of the list. This is what the last return does. Commented Jun 17, 2013 at 5:23
  • @Giorgio,Why wouldn't only a function call have sufficed,why a return is needed before that? Commented Jun 17, 2013 at 5:29
  • 9
    Because you need to return the value that is returned by the function Commented Jun 17, 2013 at 5:32
  • 10
    Downvoters: please realize that, depending on the background of the OP, it's not at all obvious what return does. In fact, in functional languages (and some mixed ones, like Scala) return is not needed: the value of the recursive function is the value of its last expression. Simply writing search_list(l->next, x) without return would have worked in Scala! The meaning of the return statement is only obvious to programmers with an imperative background. Commented Jun 17, 2013 at 13:29
  • OP: is your code snippet written in C? Commented Jun 17, 2013 at 13:33