Don't forget to use 'break' in switch/case statements
ColdFusionI was recently attempting to broaden my skillset a bit by reading a simple introductory book that is more or less the equivalent of "Java for Dummies". In a section that talked about conditional logic, it made the statement that you should always remember to add a "break;" at the end of each case within a switch statement or the remaining conditions would be processed in after the matching one.
I was thinking at the time that I knew this was not how ColdFusion processed code using cfscript/cfcase, but I realized that I wasn't entirely sure how this was handled in cfscript.
I decided to run a quick test and found that it behaves identically to Java. To set up a baseline for my test, I made a quick switch/case in tags like this:
As expected when I ran this, the string "second" appeared on the screen. In atempt to do the exact same thing in script, only excluding the "break" after each case, I ran this:
Sure enough, it behaved exactly as the Java book had described that Java would handle this as the screen displayed: "secondthird".
So, understanding this behavior, is there something useful that could be accomplished by purposefully omitting breaks?





Loading....