The ColdFusion Server-side scripting language, CFScript, offers ColdFusion functionality in script syntax.
This JavaScript-like language offers the same control flow, but without tags. CFScript regions are bounded by <cfscript
> and </cfscript
> tags. You can use ColdFusion expressions, but not CFML tags, inside a CFScript region.
The following example shows how you can rewrite a block of cfset
tags in CFScript:
<cfset employee=structnew()> <cfset employee.firstname=Form.firstname> <cfset employee.lastname=Form.lastname> <cfset employee.email=Form.email> <cfset employee.phone=Form.phone> <cfset employee.department=Form.department> <cfoutput> About to add #Form.firstname# #Form.lastname#<br> </cfoutput>
<cfscript> employee=StructNew(); employee.firstname=Form.firstname; employee.lastname=Form.lastname; employee.email=Form.email; employee.phone=Form.phone; employee.department=Form.department; WriteOutput("About to add " & Form.firstname & " " & Form.lastname); </cfscript>
The WriteOutput
function appends text to the page output stream. Although you can call this function anywhere within a page, it is most useful inside a cfscript
block. For information on the WriteOutput
function, see the CFML Reference.
CFScript supports the following statements:
if-else |
while |
do-while |
for |
break |
continue |
for-in |
switch-case |
var (in custom functions only) |
return (in custom functions only) |