Having one exit point (return) from a function is a good thing. Here is an example of a single exit point:
int MyArray::indexOfElement(int elementToFind){ int foundIndex = ELEMENT_NOT_FOUND; for(int i = 0; i < m_numberOfElements; ++i){ if(this->elementAtIndex(i) == elementToFind){ foundIndex = i; break; } } return foundIndex; }
Having multiple exit points can be bad. Here is an example of multiple exit points:
int MyArray::indexOfElement(int elementToFind){ for(int i = 0; i < m_numberOfElements; ++i){ if(this->elementAtIndex(i) == elementToFind){ return i; } } return ELEMENT_NOT_FOUND; }
Why are multiple exit points bad? Because I say so. They are also bad for these two reasons:
