[ACCEPTED]-Exit a function in case condition is not satisfied-cocoa-touch
Accepted answer
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
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 :)
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.