Download presentation
Presentation is loading. Please wait.
Published byShannon Mason Modified over 6 years ago
1
Variables and Conditions Nicholas Tunney Senior Software Architect
2
What will we cover? Variable Basics Types of Variables
ColdFusion Variable Scopes Conditional Logic
3
What is a variable? Container Name/value pair Dynamic (changing)
Variables permit our programs to work with values that can't be known at design time or that may change from their original value
4
Data typing Different data types hold different types of values
String: “Hello World” Int: 42 Structure: Object (Car) Name Nic Tunney Presenter True Age 28 getModel() Return string getMake() accelerate()
5
Strong data typing Must declare a variable’s type before it can be used String myName; Int myAge; Company myEmployer; Strongly typed languages Java C#
6
Weak data typing Language determines type of variable at runtime dynamically Weakly typed languages are NOT untyped languages Weakly typed languages Smalltalk ColdFusion
7
ColdFusion data types Simple: Strings (lists) Integers Real numbers
Boolean values Date-time values
8
ColdFusion data types Binary Object Raw data such as images COM CORBA
Java Web Services ColdFusion Components
9
ColdFusion data types Complex: Arrays Structures Queries
10
ColdFusion Arrays Array: Array Element
A set of sequentially indexed elements having the same type of data. Each element of an array has a unique identifying index number. Changes made to one element of an array do not affect the other elements. Array Element Individual item stored within an array
11
One Dimensional Arrays
Simple ordered stack of values Addressable Refer to each element using [x] myArray[1], myArray[2] myArray 1 Nic 2 Kelly 3 Simon
12
Two Dimensional Arrays
Collection of ordered values Addressable Refer to each element as [x][y] myArray[1][1], myArray[2][2] myArray 1 2 Nic Tunney Simon Horwith
13
ColdFusion Structures
A container (variable) that’s holds a group of data objects. Unlike arrays, each data object in a structure generally is of a different type Structures are unordered Addressable myStruct.speaker, myStruct[“topic”] myStruct speaker Nic Tunney topic Variables isActive true
14
ColdFusion Queries Series of 1 or more rows with column or field values for each row Addressable products.price – refers to current row products.price[2] – specifies row myQuery id price description 001 29.99 Widget 002 59.99 Foobar
15
Objects Objects are fundamentally different from all other data types in that they encapsulate both data and behavior Objects are real world representations Car getMake(): string addGas(gallons): void accelerate(): void
16
ColdFusion Scopes A variable typically has a lifespan and a scope
lifespan: how long the system keeps a reference to a variable scope: location from which variable is visible In ColdFusion, a variable's scope and lifespan are bound together in a single attribute, scope, which is prefixed to the variable name
17
ColdFusion Scopes prefix visibility prefix required lifespan
application everywhere in same app Yes life of application attributes within custom tag (for variables passed into custom tag) current request caller within custom tag (for variables on calling page) cgi everywhere No client everywhere in same application for an individual user varies by purge timeframe cookie everywhere in all apps on domain varies; set by cookie form request server everywhere by all apps on single server varies by server timeout setting session everywhere in same app for an individual user varies by session timeout setting url variables local to page/CFC and any included pages (default)
18
Conditional Expressions
A conditional is an expression that can be evaluated to a boolean value Certain actions are taken depending on true versus false
19
<cfif> Evaluates an expression <cfif expression>
Do Something </cfif>
20
<cfelseif> Allows us to add additional conditions if first condition is false <cfif expression> Do something <cfelseif different_expression> Do something else </cfif>
21
<cfelse> Handles the false condition of a <cfif> block
“Catch All” condition <cfif expression> Do something <cfelse> Do something else </cfif>
22
<cfswitch><cfcase>
Rule of threes Evaluates expression and passes control to the matching <cfcase> tag <cfswitch expression = "expression"> <cfcase value = "value" delimiters = "delimiters"> HTML and CFML tags </cfcase> … additional <cfcase></cfcase> tags … <cfdefaultcase> </cfdefaultcase> </cfswitch>
23
Operators ColdFusion Operator Equivalent to IS, EQUALS, EQ = LT <
LTE, LE <= GT > GTE, GE >= IS NOT, NEQ <> CONTAINS N/A DOES NOT CONTAIN
24
Conclusion Variables are dynamic (changing)
Variables give context and constraint to values Experiment with complex variables to help ease coding and maintenance time ColdFusion is a loosely typed language, but not untyped Conditionals allow us to execute commands based on the result of some run time boolean value
25
Conclusion This presentation laid the ground work for using variables and conditions in ColdFusion Next steps CF Tags Functions for complex data types AboutWeb Training Fast Track to ColdFusion Custom Class
26
Thanks!
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.