Nested IF Statements

Team-Fly    

ColdFusion® MX: From Static to Dynamic in 10 Steps
By Barry Moore
Table of Contents
Step 4.  Controlling Program Flow


If you have to check for a complex set of conditions, you can nest <CFIF> statements inside other <CFIF> statements. For example, after I brought the car home intact several times in a row and began to show my father what a trustworthy member of society I really was, he would only give me the third degree if I came home looking guilty.

 <!--- Start outer IF statement --->  <CFIF LooksGuilty IS "Yes">  <!--- If Barry looks guilty run this IF statement code.              If we find any match here, we run that code and then              jump out of both IF statements and continue with the              rest of the page        --->        <CFIF CarDented IS "YES">              Butt kicking<BR>          <CFELSEIF EmptyBeerCansInTrunk IS "Yes">              Night in the box<BR>          <CFELSEIF AshesInAshtray IS "Yes">              Barry is grounded<BR>          <CFELSE>              Eye Barry suspiciously and check the quantity of fuel in the gas tank<BR>        </CFIF>    <CFELSE>        <!--- Run this code if Barry does not look guilty --->         He is not such a bad kid after all.  </CFIF>  <!--- the rest of the page --->

When I came home, Dad would start the outer IF statement. If I looked guilty, he would drop into the nested IF statement, and we would go through the third degree about the car. If he found anything while running the nested IF statement (say, AshesInTheAshtry IS "Yes"), that code would run (I would be grounded), and we would jump out of both IF statements and continue on with the rest of the page. If I did not look guilty, the <CFELSE> code from the outer IF statement would run, and once again, Dad would come to the conclusion that I was not such a bad kid.


    Team-Fly    
    Top
     



    ColdFusion MX. From Static to Dynamic in 10 Steps
    ColdFusion MX: From Static to Dynamic in 10 Steps
    ISBN: 0735712964
    EAN: 2147483647
    Year: 2002
    Pages: 140
    Authors: Barry Moore

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