CFScript: Difference between revisions

Content deleted Content added
m rm contraction
Tags: Mobile edit Mobile app edit iOS app edit App section source
 
(3 intermediate revisions by 3 users not shown)
Line 4:
 
== Usage ==
Unless it's is within a pure script-based ColdFusion Component, all CFScript code must be contained within a CFScript tag pair as follows:
It is considered best practice to write ColdFusion Components and all business logic in CFScript and to use [[CFML]] only in .cfm files amongst [[HTML]].
 
Unless it's within a pure script-based ColdFusion Component, all CFScript code must be contained within a CFScript tag pair as follows:
<syntaxhighlight lang="cfm">
<cfscript>
xParam = 115;
yParam = 200;
color = 'FFCC99';
</cfscript>
</syntaxhighlight>
Line 43 ⟶ 41:
<syntaxhighlight lang="cfm">
<cfscript>
qGetData = new Query();
qGetData .setDataSource('#APPLICATIONApplication.datasource#');
qGetData .setSQL('SELECT column1, column2 FROM table WHERE 1');
qDateResult = qGetData .Execute().getResult();
</cfscript>
</syntaxhighlight>
Line 95 ⟶ 93:
</syntaxhighlight>
 
=== Try / Catchcatch ===
<syntaxhighlight lang="javascript">
try {
Line 123 ⟶ 121:
=== Looping ===
 
==== For Looploop ====
<syntaxhighlight lang="javascript">
for (i=1; i LTE<= ArrayLen(array); i=i+1) {
WriteOutput(array[i]);
}
Line 141 ⟶ 139:
</syntaxhighlight>
 
==== While Looploop ====
<syntaxhighlight lang="javascript">
x = 0;
while (x LT< 5) {
x = x + 1;
WriteOutput(x);
Line 151 ⟶ 149:
</syntaxhighlight>
 
==== Do / Whilewhile Looploop ====
<syntaxhighlight lang="javascript">
x = 0;
do {
x = x + 1;
WriteOutput(x);
} while (x LTE<= 0);
// Outputs: 1
</syntaxhighlight>
 
==== Looping over an Arrayarray ====
<syntaxhighlight lang="javascript">
for (item in array) {