go to previous page   go to home page   go to next page

Answer:

The structured version of the function is easily modified to meet the new requirements.


Easily Modified Structure

int countPunct( char *p )
{
  count = 0;
  while ( p )
  {
    if  ( ispunct( *p ) ) count++ ;
    p++ ;
  }
  return count;
}

Actually, with this tiny function, both versions are easily modified to meet the changed requirements. But revisions might be difficult if you had a longer function with several early returns. One of the advantages of structured programming is that changes are more easily made than with poorly structured code. The advantages of early returns might be offset by difficulty in making revisions.


QUESTION 10:

If early returns are sometimes OK in a loop, what about continue ?