What is the best way of writing code to exit a function in case condition is not satisfied?
e.g I have a function
-(IBAction) moreDetails
{
if (condition)
//condition not satisfied...exit function
else
continue with the function
}
Can i simply write return ?
Yes. “return” returns immediately from the current method/function. If the function/method returns a value then you need to provide a return value: “return NO, return 3, return @”string”, and so on.
I generally prefer this structure:
to this:
because fewer lines are indented