Can return and else statements be used interchangable in CFScript?

Posted by Mel on Stack Overflow See other posts from Stack Overflow or by Mel
Published on 2011-01-07T19:46:35Z Indexed on 2011/01/07 19:53 UTC
Read the original article Hit count: 135

I would like to know your opinion on using return and else statements interchangeably in CFScript. I generally use the following syntax:

if (something) {
  // Do something
}
else {
  // Do something else
}

It recently occurred to me I could do this instead:

if (something) {
  // Do something
  return;
}
// Do something else

Would those two styles yield a different end result? I like not having to wrap code in an else statement. My thinking is that if the if statement evaluates true and returns, the code below it will not run. If it does not evaluate true, then the code below it will run regardless of whether it is wrapped in an else statement or not.

Does that sound write?

© Stack Overflow or respective owner

Related posts about scripting

Related posts about coldfusion