Shaun Mccran

My digital playground

12
A
U
G
2008

Using if and else in Cfscript

Every CF developer is intimately familiar with the code. I was recently re-writing something that was entirely CfScript based, apart from a large chunk of 'IFS' in the middle of the template. So I thought I'd re-write it into CfScript. Turns out its very easy!

view plain print about
1<cfscript>
2 IF (condition is met)
3 action code;
4
</cfscript>

Pretty straight forward. Looks very similar to the if-else statement.

view plain print about
1<cfscript>
2 IF (condition is met)
3 action code;
4 ELSE
5 action other code;
6
7
</cfscript>

Enclose the actionable code in {} and it will perform many 'stacked' functions.

view plain print about
1<cfscript>
2 IF (condition is met)
3 {
4 action code;
5 action more code;
6 }
7
</cfscript>

I think I actually prefer this way of writing the logic, as its much closer in syntax to Action Script.

TweetBacks
Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
Back to top