• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL

Part V: Common ColdFusion Programming Te... > Conditional Logic Problems and Solut...

Chapter 14. Conditional Logic Problems and Solutions

One of the biggest advantages to using a full-fledged programming language for web application development is the capability to use flow conditional processing to generate dynamically the content of a page. Although it’s possible to use only SQL queries to generate dynamic content in a linear fashion directly from a database, the conditional logic capabilities of a programming language can add immeasurably to the flexibility of your application. Most programming languages have conditional logic constructs such as if-then-else and switch statements, and ColdFusion is certainly no exception. CFML has special tags defined that can be used for application flow control.

In this chapter, you will learn how to use the CFML flow control tags to perform conditional processing in an application. CFML provides tags for standard programming logic, including if-elseif-else, switch, and loop logic.

Using conditional logic tags to control execution flow based on an expression gives you great flexibility in generating dynamic content. It is possible to generate very different page content depending on the data you are presenting. For example, an e-commerce application may need to generate an image tag if a picture of a product is available—or not if one isn’t. Another possibility is to display an “out of stock” message only if a particular item cannot be found in the inventory. Figure 14.1 shows several common conditional logic structures. This chapter will present an overview of the flow control tags provided by ColdFusion MX. It consists of the following sections:

  • Introduction to conditional logic



  • Using CFLOOP and CFBREAK

  • Using conditional logic in your application

  • Testing the application



Not a subscriber?

Start A Free Trial

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