tags:

views:

127

answers:

1

I'm pretty much new to Objective C but I've had some experience in Visual Basic. What's the equivalent of the Exit Sub statement to stop executing code if conditions aren't met? I'm talking along the lines of

If Some.Condition.Is.Not.Met Then
    Exit Sub //Please don't execute any more code in this method

Is this the correct way to make it work?

-(BOOL)methodThatQuitsOut {
    [SomeCode GoesHere];
    Other.code = Goes.here;
    if (condition != present) {
        return NO;
    }
    Does this code continue to run?;
}
+5  A: 

returning from a function does just that; it returns, and control is passed back to the call-e. So no, the code below the return will not execute.

I would note that this would have taken about 30 seconds to test yourself.

Ed Swangren
I wasn't at my desk when typing this =) I was at work, thinking about what code I was going to write later. Thanks for the answer
JustinXXVII