It's considered a bad pratice use return to end a function?

后端 未结 5 1193
忘了有多久
忘了有多久 2021-01-19 10:46

I\'m a PHP and ActionScript developer, and in some of my functions I use return to end it. Example:

private function lolsome(a:String):void
{
           


        
5条回答
  •  死守一世寂寞
    2021-01-19 11:40

    Nope. Not at all. It's often an important piece of control flow, in fact:

    for x in someiterable:
        if somecondition:
            return somevalue
    return None
    

    This might come up if you were iterating over a sequence looking for something that satisfies a particular condition. If you find that something, you return it and prevent any further processing. If you never find it, you return a default value.

提交回复
热议问题