Switch Statements

All the conditional processing used thus far has involved <cfif> statements. But as I stated at the beginning of this chapter, ColdFusion also supports another form of conditional processing: switch statements.

The best way to understand switch statements is to see them used. Listing 9.10 should be saved as file switch.cfm.

When you have executed Listing 9.10, you’ll notice that it does exactly what Listing 9.5 (file if5.cfm) does. The code here is very different, however.

Listing 9.10. switch.cfm
<!--- Name: switch.cfm Author: Ben Forta (ben@forta.com) Description: Demonstrate use of <cfswitch> and <cfcase> Created: 07/01/2007 ---> <html> <head> <title>Switch</title> </head> <body> <!--- Get day of week ---> <cfset dow=DayOfWeek(Now())> ...

Get Adobe ColdFusion 8 Web Application Construction Kit, Volume 1: Getting Started now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.