Skip to content

Instantly share code, notes, and snippets.

@cocolote
Last active August 29, 2015 14:24
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 cocolote/067cf8eff71aa9474388 to your computer and use it in GitHub Desktop.
Save cocolote/067cf8eff71aa9474388 to your computer and use it in GitHub Desktop.
Decision Making structures ColdFusion

#Decision Making Structures

  • Operators

CFML and CFScirpt | CF8+ CFScript Only --- | --- | --- IS, EQUAL, EQ | == IS NOT, NOT EQUAL, NEQ | != GT, GREATER THAN, LT, LESS THAN, GTE, LTE | >, <, >=, <= CONTAINS | N/A DOES NOT CONTAIN | N/A

  • Join conditions
CFML and CFScript CF8+ CFScript Only
AND &&
OR // (two vertical bars)
NOT !
XOR N/A
EQV N/A
IMP N/A

What if?

  • CFML
<cfif n1 GTE n2>
    <h1>N1 is greater or equal than N2</h1>
<cfelse>
    <h1>N1 is less or equal than N2</h1>
</cfif>
  • CFScript
<cfscript>
if (N1 >= N2) {
    ...some code...;
} else {
    ...some other code...;
}
</cfscript>

What if or if?

  • CFML
<cfif n1 GT n2>
    <h1>N1 is greater than N2</h1>
<cfelseif n1 EQ n2>
    <h1>N1 is equal to N2</h1>
<cfelse>
    <h1>N1 is less than N2</h1>
</cfif>
  • CFScript
<cfscript>
if (N1 > N2) {
    ...greater than code...;
} else if (N1 == N2) {
    ...code for equality...;
} else {
    ...less than code...;
}
</cfscript>

Switch case

  • CFML
<cfswitch expression="#myVar#">
    <cfcase value="1">
        ...code...
    </cfcase>
    <cfcase value="9,10"> <!---9 or 10--->
        ...code...
    </cfcase>
    <cfdefaultcase>
        ...finally...
    </cfdefaultcase>
</cfswitch>
  • CFScript
<cfscript>
switch (myVar) {
    case 1:
        ...some code...;
        break;
    case 9:
        ...some code...;
        break;
    default:
        ...default code...;
        break;
}
</cfscript>

Ternary operation

<cfscript>
x = (myVar == 1) ? 1 : 277;
</cfscript>

Variables Scope

Prefix Scope What is for? Required?
var current page default NO
URL current page values pased on the query string NO
CGI any page server environment variables NO
FORM current page values pased through a form NO
COOKIE any page values to keep in the client machine NO
CLIENT any page varaibles created using the client prefix NO
ARGUMENTS local to the function or component method values required by the function or method NO
SESSION any page for the duration of a client session client info YES
APPLICATION any page to all users until application restarted info global to the application YES
SERVER any page that is delivered from specific server server information YES
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment