Adobe 38043740 - ColdFusion Standard - Mac Development Manual page 39

Developing applications
Hide thumbs Also See for 38043740 - ColdFusion Standard - Mac:
Table of Contents

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
The CFML Programming Language
cfif, cfelseif, and cfelse
The
,
, and
cfif
cfelseif
cfelse
The
tag tests a condition and executes its body if the condition is True.
1
cfif
2
If the preceding
(or
cfif
its body if that condition is True.
3
The
tag can optionally follow a
cfelse
preceding tags' test conditions are False.
The following example shows the use of the
"Date," the date displays; if the value is "Time," the time displays; otherwise, both the time and date display.
<cfif type IS "Date">
<cfoutput>#DateFormat(Now())#</cfoutput>
<cfelseif type IS "Time">
<cfoutput>#TimeFormat(Now())#</cfoutput>
<cfelse>
<cfoutput>#TimeFormat(Now())#, #DateFormat(Now())#</cfoutput>
</cfif>
cfswitch, cfcase, and cfdefaultcase
The
,
, and
cfswitch
cfcase
expression. ColdFusion processes these tags as follows:
1
The
tag evaluates an expression. The
cfswitch
optionally includes
cfdefaultcase
2
Each
tag in the
cfcase
cfswitch
by the expression in the
cfswitch
tag. If two
cfswitch
cfcase
3
If none of the
tags match the value determined by the
cfcase
a
tag, ColdFusion runs the code in the
cfdefaultcase
Note: Although the
cfdefaultcase
it at the end of the
cfswitch
The
tag provides better performance than a cfif tag with multiple
cfswitch
processing is commonly used when different actions are required based on a string variable such as a month or request
identifier.
The following example shows switch processing:
tags provide if-then-else conditional processing, as follows:
) test condition is False, the
cfelseif
tag and zero or more
cfif
,
cfif
cfelseif
tags let you select among different code blocks based on the value of an
cfdefaultcase
cfswitch
tag.
tag body specifies a value or set of values. If a value matches the value determined
tag, ColdFusion runs the code in the body of the
tags have the same condition, ColdFusion generates an error.
tag does not have to follow all
statement.
Last updated 1/20/2012
tag tests another condition and executes
cfelseif
tags. Its body executes if all the
cfelseif
, and
tags. If the value of the type variable is
cfelse
tag body contains one or more
cfcase
tag, and the
cfswitch
tag body.
cfdefaultcase
tags, it is good programming practice to place
cfcase
tags, and is easier to read. Switch
cfelseif
tags and
cfcase
tag and then exits the
tag body includes
cfswitch
34

Advertisement

Table of Contents
loading

This manual is also suitable for:

Coldfusion 9

Table of Contents