[ACCEPTED]-Exit a function in case condition is not satisfied-cocoa-touch

Accepted answer
Score: 22

Yes. "return" returns immediately from 6 the current method/function. If the function/method 5 returns a value then you need to provide 4 a return value: "return NO, return 3, return 3 @"string", and so on.

I generally prefer 2 this structure:

void f()
{
    if ( ! conditionCheck )
        return;
    // long code block
}

to this:

void f()
{
    if ( conditionCheck )
    {
        // long code block
    }
}

because fewer lines 1 are indented

Score: 5

Yes - you should use return. Because your 3 method returns void, no need for anything 2 else. I'd write more, but there's not much 1 else to it :)

More Related questions