This one time, at band camp, Tim Leslie wrote:
>On 5/11/07, Michael Chesterton <[EMAIL PROTECTED]> wrote:
>>
>>Is there some sort of common practice about where to return from a 
>>function?
>>I've got this vague recollection of not returning from just anyway. ie
>>
>>for(foo)
>> if(test1)
>>  return false
>> else if(test2)
>>  return false
>>return true
>>
>>against
>>
>>valid = true
>>for(foo)
>> if(test1)
>>  valid = false
>> else if(test2)
>>  valid = false
>>if(valid)
>> return true
>>else
>> return false
>>
>
>As a general rule each function should have a single return statement,
>unless there's a good reason not to. Sometimes the structure of a

Master the rule, and then break it.

If you make the function unreadable by sticking to the rule, then don't
stick to the rule :)

Note that your two examples have different semantics if you're iterating
over 'foo'.
_______________________________________________
coders mailing list
[email protected]
http://lists.slug.org.au/listinfo/coders

Reply via email to