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

Lesson 7. Using Conditional Logic

Lesson 7. Using Conditional Logic

One of the main elements of a dynamic Web site is the capability of making decisions on the fly. Deciding what navigation to include or what information to display is crucial. Visitors to your site expect to be kept informed with current data, so being able to display, for example, the status of an item, may be a critical component of your site. Also, by dynamically including your subnavigation, you can save yourself countless hours of update time by only having to make changes in one place. There are several related components in ColdFusion that will aid you in accomplishing these tasks: <cfif>, <cfelse>, and <cfelseif>.

A <cfswitch> statement is just one of several tools you have at your disposal to help make your site more dynamic.

“If, else” logic has been around in the programming world for ages. Simply stated, the logic dictates that if a certain item exists or a condition is true, then do one thing (“x”), otherwise do another (“y”). You can think of it like being at a stop light: you can choose to go one way or the other. The decision is usually dependent on where you are heading: home is to the left, the mall is to the right.

In this lesson, we'll work with this conditional logic to help you serve up dynamic information and answers to the customers who visit your site. We'll also cover two other related tags, cfswitch and cfloop, both of which are methods for speeding up processes that can become cumbersome if you have a lot of conditions to meet.


In this lesson you will:

  • Learn that many tasks that your Web site needs to perform can be controlled by conditional logic

  • Use if, else, and elseif statements to control page flow

  • Include dynamic subnavigation code in your page

  • Learn when to use looping to execute a piece of code repeatedly


This lesson take approximately 1 hour and 30 minutes to complete.


Starting Files:





Completed Files:








Not a subscriber?

Start A Free Trial

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