Re: while (1) vs. for ( ;; )



Richard Heathfield wrote:
>
> Alan Balmer said:
>
<>
> [avoiding multiple returns]
>
<>
> That's a reasonable argument. Here's another, which is diametrically
> opposed. :-)
>
> There are two tasks here - the validation of parameters, and the task for
> which the function was actually written. Now, there may well be times when
> you know perfectly well that the parameters are valid, because it's
> actually impossible for them not to be valid. And there are times when
> you're not sure.
>
> In the cases where you are sure the parameters are okay, you can call the
> function directly, avoiding the overhead of the parameter check. (You could
> reasonably add assertion checks here, since they cannot possibly fire if
> your program is correct.)
>
> When you're not sure, you call the validation function - which either calls
> the "do it" function directly or, perhaps slightly more cleanly, returns an
> "everything's fine" value, after which you can proceed to call the "do it"
> function yourself.
>
IIRC that's one reason, why COBOL has multiple entry points into functions.
.



Relevant Pages