Skip to content

Instantly share code, notes, and snippets.

Created June 1, 2015 17:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/79d1a9adeea8c2b3d0b6 to your computer and use it in GitHub Desktop.
Save anonymous/79d1a9adeea8c2b3d0b6 to your computer and use it in GitHub Desktop.
TryCF Gist
<cfscript>
// randomly set truthy/falsy
booleanExpression = !!randRange(0,1);
anotherBooleanExpression = !!randRange(0,1);
writeOutput('<h2>Single statements - no curlies</h2>');
writeDump({"inputs":{"booleanExpression":booleanExpression,"anotherBooleanExpression":anotherBooleanExpression}});
if (booleanExpression)
writeOutput( "'booleanExpression' was true" ); // single statement executed if booleanExpression is true
else if(anotherBooleanExpression)
writeOutput( "'anotherBooleanExpression' was true" ); // single statement executed if anotherBooleanExpression is true
else
writeOutput( "Neither 'anotherBooleanExpression' or 'booleanExpression' were true" ); // single statement executed if condition(s) are false
// randomly set truthy/falsy
booleanExpression = !!randRange(0,1);
anotherBooleanExpression = !!randRange(0,1);
writeOutput('<h2>Multiple statements - with curlies</h2>');
writeDump({"inputs":{"booleanExpression":booleanExpression,"anotherBooleanExpression":anotherBooleanExpression}});
if (booleanExpression) {
writeOutput( "'booleanExpression' was true" ); // multiple statements executed if booleanExpression is true
} else if(anotherBooleanExpression) {
writeOutput( "'anotherBooleanExpression' was true" ); // multiple statements executed if anotherBooleanExpression is true
} else {
writeOutput( "Neither 'anotherBooleanExpression' nor 'booleanExpression' were true" ); // multiple statements executed if condition(s) are false
}
</cfscript>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment