"Yes, if you really want to avoid multiple returns then this is the way to do it. But it isn't as easy to read as the solution given by BioPhysEngr (with my correction). "

If you follow the coding standard of "Single entry, single return" it is easier to debug. If you set a breakpoint at the return statement at the end of the function, you can be sure it will be hit. If there are multiple returns embedded throughout the function, you would have to set breakpoints at every return statement, and it is possible that some may be overlooked. There is a reason the software experts put the "Single entry, single return" rule into the standard. They obviously thought it was a cleaner way to write a function. I agree with their thinking, but I realize that some software people (very intelligent & knowledgeable people) today do not always agree; I don't lose any sleep over it since I don't have to maintain their code.