• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint

Using <cfswitch>

When you have several if statements like you had above, it is sometimes better to use <cfswitch>. You can use <cfswitch> when all your conditional logic revolves around one expression, such as the productqty variable we worked with in the last section. For example, in each of the <cfif> statements, you were comparing the product quantity to another value, and outputting a different variable based on that number. In the case of <cfswitch>, the <cfswitch> statement will look at that expression and apply one of many cases. A case is one condition for the specific expression; basically, it's your <cfif> statement without the <cfif>. For example, if the product quantity were 1, the case with the value of 1 would be executed. Using a <cfswitch> statement can come in handy when you want to include different blocks of code based on a variable. It is also a little faster to execute than multiple <cfif> statements. By dynamically including files, you can dynamically include all of your subnavigation.

NOTE

The <cfswitch> type of logic is so powerful that an entire programming methodology, FuseBox, has sprung up around it. For more information go to www.fusebox.org.



PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint