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

19. Scripting > 19.3. Flow Control and Looping

Flow Control and Looping

CFScript contains a number of statements to handle flow control and looping, as we’ll discuss in this section. Note that you can’t use any CFML tags within a cfscript block.

if/else

The if/else statement has the same functionality as the cfif and cfelse (and by extension, cfelseif) tags in regular CFML. The if statement can be used alone, as in:

if (expression)
  statement;

Or it can be used with the else statement, as in:

if(expression)  
  statement;
else
  statement;

You can also use the else and if statements in combination to achieve the same results as the cfelseif tag:

if (expression)
  statement;
else if (expression)
  statement;
else
  statement;

To understand the differences between the cfif/cfelse tags and the ifelse statement, let’s first consider an example that uses the cfif and cfelse tags. Example 19-3 assigns the current year to a variable called TheYear. The cfif and cfelse tags are then used to determine whether the current year is a leap year. The results are then written to the browser.


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


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