Lesson 7. Using Conditional Logic

I l @ ve RuBoard

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.

WHAT YOU WILL LEARN

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

APPROXIMATE TIME

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

LESSON FILES

Starting Files:

Lesson7\Start\productstatus.cfm

Lesson7\Start\dynamicnav.cfm

Lesson7\Start\basicform.cfm

Lesson7\Start\formoutput.cfm

Completed Files:

Lesson7\Complete\productstatus.cfm

Lesson7\Complete\dynamicnav.cfm

Lesson7\Complete\aboutnav.cfm

Lesson7\Complete\basicform.cfm

Lesson7\Complete\formoutput.cfm

I l @ ve RuBoard


Macromedia ColdFusion 5. Training from the Source
Macromedia ColdFusion 5 Training from the Source (With CD-ROM)
ISBN: 0201758474
EAN: 2147483647
Year: 2002
Pages: 99
Authors: Kevin Schmidt

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net