for (i=1;i LTE ArrayLen(array);i=i+1) {
WriteOutput(array[i]);
}
function funky(mojo) {
var dojo = 0;
if (arguments.mojo EQ dojo) {
return "mojo";
}
else { return "no-mojo"; }
}
switch(fruit) {
case "apple":
WriteOutput("I like Apples");
break;
case "orange":
WriteOutput("I like Oranges");
break;
default:
WriteOutput("I like fruit");
}
if (fruit IS "apple") {
WriteOutput("I like apples");
}
else if (fruit IS "orange") {
WriteOutput("I like oranges");
}
else {
WriteOutput("I like fruit");
}
x = 0;
while (x LT 5) {
x = x + 1;
WriteOutput(x);
}
//OUTPUTS 12345
x = 0;
do {
x = x+1;
WriteOutput(x);
} while (x LTE 0);
// OUTPUTS 1
foo = "bar";
mojo = 1; //THIS IS A COMMENT
component extends="Fruit" output="false" {
property name="variety" type="string";
public boolean function isGood() {
return true;
}
private void eat(required numeric bites) {
//do stuff
}
}
try {
throw(message="Oops", detail="xyz"); //CF9+
} catch (any e) {
WriteOutput("Error: " & e.message);
rethrow; //CF9+
} finally { //CF9+
WriteOutput("I run even if no error");
}
struct = StructNew();
struct.one = "1";
struct.two = "2";
for (key in struct) {
WriteOutput(key);
}
//OUTPUTS onetwo
/* This is a comment that can span multiple lines */
cars = ["Ford","Dodge"];
for (car in cars) {
WriteOutput(car);
}
//OUTPUTS FordDodge
cars = QueryNew("make,model",
"cf_sql_varchar,cf_sql_varchar",
[["Ford", "T"],["Dodge","30"]]);
for (car in cars) {
WriteOutput("Model " & car.model);
}
//OUTPUTS Model TModel 30
include "template.cfm";
transaction {
//do stuff
if (good) {
transaction action="commit";
else {
transaction action="rollback";
}
}
product = {id=1, name="Widget"};
fruit = ["apples", "oranges"];
for (row in query) {
if (row.skip) {
continue;
}
//...
}
for (row in query) {
if (row.currentrow > 10) {
break;
}
//...
}
; after each statement!Questions, comments, criticism, or requests can be directed Here
Copyright © 2007-2021 Peter Freitag (http://www.petefreitag.com/), All Rights Reserved. This document may be printed freely as long as this notice stays intact.