<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Simon Whatley &#187; variables</title>
	<atom:link href="http://www.simonwhatley.co.uk/tag/variables/feed" rel="self" type="application/rss+xml" />
	<link>http://www.simonwhatley.co.uk</link>
	<description>The opposite of every great idea is another great idea</description>
	<lastBuildDate>Wed, 02 Nov 2011 09:28:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>How to Protect Your Website from a Malicious Attack</title>
		<link>http://www.simonwhatley.co.uk/how-to-protect-your-website-from-a-malicious-attack</link>
		<comments>http://www.simonwhatley.co.uk/how-to-protect-your-website-from-a-malicious-attack#comments</comments>
		<pubDate>Mon, 18 Aug 2008 12:54:20 +0000</pubDate>
		<dc:creator>Simon</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Adobe]]></category>
		<category><![CDATA[Application.cfc]]></category>
		<category><![CDATA[Application.cfm]]></category>
		<category><![CDATA[attack]]></category>
		<category><![CDATA[best practice]]></category>
		<category><![CDATA[Business]]></category>
		<category><![CDATA[cfquery]]></category>
		<category><![CDATA[cfqueryparam]]></category>
		<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[ColdFusion Administrator]]></category>
		<category><![CDATA[cross-site scripting]]></category>
		<category><![CDATA[database server]]></category>
		<category><![CDATA[Databases]]></category>
		<category><![CDATA[encryption]]></category>
		<category><![CDATA[firewall]]></category>
		<category><![CDATA[how to]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Manitoba]]></category>
		<category><![CDATA[Mark Kruger]]></category>
		<category><![CDATA[prevention]]></category>
		<category><![CDATA[protection]]></category>
		<category><![CDATA[raw processing]]></category>
		<category><![CDATA[RDBMS]]></category>
		<category><![CDATA[script protect]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[software releases]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Injection]]></category>
		<category><![CDATA[url]]></category>
		<category><![CDATA[variables]]></category>
		<category><![CDATA[vulnerability]]></category>
		<category><![CDATA[Web Application Hacker]]></category>
		<category><![CDATA[web code]]></category>
		<category><![CDATA[Web Security]]></category>
		<category><![CDATA[Web Server]]></category>
		<category><![CDATA[Web Servers]]></category>
		<category><![CDATA[webserver]]></category>
		<category><![CDATA[XSS]]></category>

		<guid isPermaLink="false">http://www.simonwhatley.co.uk/?p=809</guid>
		<description><![CDATA[Every seasoned developer will know that protecting your website from a hacker is a top priority, whether for your own reputation or for maintaining your company's reputation and log-term revenue prospects.]]></description>
			<content:encoded><![CDATA[<p>Every seasoned developer will know that protecting your website from a hacker is a top priority, whether for your own reputation or for maintaining your company&#8217;s reputation and log-term revenue prospects.</p>
<p><strong>Why should you be worried about security?</strong></p>
<p>The Web is changing many of the assumptions that people have historically made about computer security and publishing. As the Internet makes it possible for web servers to publish information to millions of users, it also makes it possible for computer hackers, crackers, criminals, vandals, and other &#8220;bad guys&#8221; to break into the very computers on which the web servers are running. Once subverted, web servers can be used by attackers as a launching point for conducting further attacks against users and organisations.</p>
<p>It is considerably more expensive and more time-consuming to recover from a security incident than to take preventative measures ahead of time.</p>
<p>This blog post started on the premise of protecting your website from a <a href="http://en.wikipedia.org/wiki/SQL_injection" title="Wikipedia: SQL Injection" target="_blank" rel="nofollow">SQL Injection</a> Attack. However, it is also appropriate to discuss, at a relatively high level, how to secure your server architecture and applications.</p>
<h3>Server-Level Security</h3>
<ul>
<li>Separate web- and database-servers on to different physical machines.</li>
<li>Secure the web- and database-servers with traditional techniques. Only authorised accounts should have the capabilities to run tasks on the machine. That means not giving admin-rights to the user account.</li>
<li>Keep servers up-to-date with the latest patches and software releases.</li>
<li>Minimise the number of services running on the server. This means limiting the services to only those required for the web- or database-servers to function.</li>
<li>Secure information in transit between servers. This may mean physically securing the network to prevent evesdropping via encryption or obfuscating the data amongst innocuous &#8216;noise&#8217;.</li>
<li>Secure the database server behind a firewall.</li>
</ul>
<p><script type="text/javascript"><!--
google_ad_client = "pub-6475233631580417";
/* 468x60 Basic */
google_ad_slot = "7117418273";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
<h3>Application-Level Security</h3>
<ul>
<li>Separate ColdFusion, the webserver and database server user accounts. They should never be under the same system account.</li>
<li>Create a database user specifically for your ColdFusion datasource and restrict it to only the activities required for the application. The user should not have database-owner rights, access to databases not relating to the application or access to the system tables.</li>
<li>Revoke privileges in the ColdFusion datasource definition to prevent the SQL commands <code>CREATE</code>, <code>DROP</code>, <code>GRANT</code>, <code>REVOKE</code> and <code>ALTER</code>.</li>
<li>General settings in the ColdFusion Administrator:
<ul>
<li>Check the <em>Disable access to internal ColdFusion Java components</em> option.</li>
<li>Check the <em>Enable Global Script Protection</em> option.</li>
<li>Add a <em>Missing Template Handler</em>.</li>
<li>Add a <em>Site-wide Error Handler</em>.</li>
<li>Reduce the <em>Maximum size of post data</em> from 100<abbr title="megabytes">MB</abbr>.</li>
<li>Enable <em>Timeout Requests</em>, and set to 60 seconds or less.</li>
<li>Disable <em>Robust Exception Handling</em> on production servers.</li>
</ul>
</li>
</ul>
<h3>Code-Level Security</h3>
<ul>
<li>Application.cfc &#8211; Set the <code>scriptProtect</code> Application variable to <code>true</code> to enable application-wide cross-site script protection.
</li>
<li>CFQueryParam &#8211; This tag, importantly, verifies the data type of a query parameter and, for <abbr title="Relational Database Management Systems">RDBMS</abbr>s that support bind variables, enables ColdFusion to use bind variables in the <acronym title="Structured Query Language">SQL</acronym> statement. Bind variable usage enhances performance when executing a <code>cfquery</code> statement multiple times.

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #800000;">&lt;cfquery</span> <span style="color: #0000ff;">name</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;qry&quot;</span> <span style="color: #0000ff">datasource</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;#APPLICATION.dsn#&quot;</span><span style="color: #800000;">&gt;</span></span>
SELECT column1, column2, column3
FROM tableName
WHERE column4 = <span style="color: #333333;"><span style="color: #800000;">&lt;cfqueryparam</span> <span style="color: #0000ff;">value</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;#variable1#&quot;</span> <span style="color: #0000ff">cfsqltype</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;cf_sql_bit&quot;</span> <span style="color: #0000ff;">/</span><span style="color: #800000;">&gt;</span></span>
AND column5 LIKE <span style="color: #333333;"><span style="color: #800000;">&lt;cfqueryparam</span> <span style="color: #0000ff;">value</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;%#variable2#%&quot;</span> <span style="color: #0000ff">cfsqltype</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;cf_sql_varchar&quot;</span> <span style="color: #0000ff;">maxlength</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;200&quot;</span> <span style="color: #0000ff;">/</span><span style="color: #800000;">&gt;</span></span>
AND column6 IN (<span style="color: #333333;"><span style="color: #800000;">&lt;cfqueryparam</span> <span style="color: #0000ff;">value</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;#variable3#&quot;</span> <span style="color: #0000ff">cfsqltype</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;cf_sql_integer&quot;</span> <span style="color: #0000ff">list</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;true&quot;</span> <span style="color: #0000ff;">/</span><span style="color: #800000;">&gt;</span></span>)
<span style="color: #333333;"><span style="color: #800000;">&lt;/cfquery&gt;</span></span></pre></div></div>

<p>There are limitations to the use of the <code>cfqueryparam</code> tag. In ColdFusion 7 for example, you cannot use them in queries using the <code>cachedWithin</code> attribute. Similarly, they cannot be used in <code>ORDER BY</code> clauses, although the use of conditional logic should resolve the need for order by variables.
</li>
<li>Functions &#8211; As a rule of thumb, validate <em>all</em> the data being passed into a query prior to it being used. ColdFusion MX 7 saw the introduction of the <code>isValid()</code> function. This function tests whether a value meets a validation or data type rule and can be used to replace a large number of type-specific functions such as <code>isArray()</code>, <code>isBinary()</code>, <code>isBoolean()</code>, <code>isDate()</code>, <code>isNumeric()</code> and <code>isSimpleValue()</code> etc.
</li>
<li>Stored Procedures &#8211; I often favour the use of stored procedures over standard queries. Not only do they add an additional level of performance, they provide an additional level of security; ColdFusion does not do any raw processing of queries in the web code, it simply passes variables down the wire to the database server.</li>
</ul>
<h3>Additional Resources</h3>
<ul>
<li>
<a href="http://www.amazon.com/Web-Security-Privacy-Commerce-2nd/dp/0596000456/ref=pd_bbs_sr_1?ie=UTF8&#038;s=books&#038;qid=1218663002&#038;sr=8-1" title="Amazon: Web Security, Privacy and Commerce" target="_blank" rel="nofollow">Web Security, Privacy and Commerce</a></li>
<li>O&#8217;Reilly&#8217;s <a href="http://www.amazon.com/Web-Application-Hackers-Handbook-Discovering/dp/0470170778/ref=pd_bbs_sr_1?ie=UTF8&#038;s=books&#038;qid=1218663073&#038;sr=1-1" title="Amazon: The Web Application Hacker's Handbook" target="_blank" rel="nofollow">The Web Application Hacker&#8217;s Handbook</a></li>
<li>Adobe&#8217;s whitepaper &#8211; <a href="http://www.adobe.com/devnet/coldfusion/articles/dev_security/coldfusion_security_cf8.pdf" title="Adobe: ColdFusion 8 Security PDF" target="_blank" rel="nofollow">ColdFusion 8 Developer Security Guidlines</a> (<abbr title="Portable Document Format">PDF</abbr>, 281k)</li>
<li>Adobe&#8217;s whitepaper &#8211; <a href="http://www.adobe.com/devnet/coldfusion/articles/dev_security/coldfusion_security_cf7.pdf" title="Adobe: ColdFusion 7 Security PDF" target="_blank" rel="nofollow">ColdFusion 7 Developer Security Guidlines</a> (<abbr title="Portable Document Format">PDF</abbr>, 217k)</li>
<li>Adobe DevNet &#8211; <a href="http://www.adobe.com/devnet/coldfusion/articles/stored_procs.html" title="Learning Stored Procedure Basics in ColdFusion 8" target="_blank" rel="nofollow">Learning Stored Procedure Basics in ColdFusion 8</a></li>
<li>0&#215;000000 # The Hacker Webzine&#8217;s article on <a href="http://www.0x000000.com/?i=610" title="The Hacker Webzine: Attacking ColdFusion" target="_blank" rel="nofollow">Attacking ColdFusion</a></li>
<li>Three part series from Mark Kruger (ColdFusion Muse) &#8211; <a title="Query String with cfqueryparam" href="http://www.coldfusionmuse.com/index.cfm/2008/7/21/query-string-with-cfqueryparam" target="_blank" rel="nofollow">Part 1</a>, <a title="Using CAST and ASCII" href="http://www.coldfusionmuse.com/index.cfm/2008/7/18/Injection-Using-CAST-And-ASCII" target="_blank" rel="nofollow">Part 2</a>, <a title="Using Order By" href="http://www.coldfusionmuse.com/index.cfm/2008/7/21/SQL-injection-using-order-by" target="_blank" rel="nofollow">Part 3</a></li>
<li>Brad Wood&#8217;s article on <a href="http://www.codersrevolution.com/index.cfm/2008/7/26/cfqueryparam-its-not-just-for-security-also-when-NOT-to-use-it" title="CFQueryParam is not just for security - When not to use it" target="_blank" rel="nofollow">CFQueryParam is not just for security</a>.</li>
</ul>
<p><script type="text/javascript"><!--
google_ad_client = "pub-6475233631580417";
/* 468x60 Basic */
google_ad_slot = "7117418273";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
]]></content:encoded>
			<wfw:commentRss>http://www.simonwhatley.co.uk/how-to-protect-your-website-from-a-malicious-attack/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Using JavaScript Assignment Operators in ColdFusion 8</title>
		<link>http://www.simonwhatley.co.uk/using-javascript-assignment-operators-in-coldfusion-8</link>
		<comments>http://www.simonwhatley.co.uk/using-javascript-assignment-operators-in-coldfusion-8#comments</comments>
		<pubDate>Tue, 26 Feb 2008 10:15:53 +0000</pubDate>
		<dc:creator>Simon</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[assignment]]></category>
		<category><![CDATA[assignment operator]]></category>
		<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[equal]]></category>
		<category><![CDATA[examples]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Meaning]]></category>
		<category><![CDATA[operators]]></category>
		<category><![CDATA[shorthand]]></category>
		<category><![CDATA[subtraction]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[variables]]></category>

		<guid isPermaLink="false">http://www.simonwhatley.co.uk/?p=431</guid>
		<description><![CDATA[In my first post in this series, I introduced <a href="/using-javascript-arithmetic-operators-in-coldfusion-8" title="Using JavaScript Arithmetic Operators in ColdFusion 8">Using JavaScript Arithmetic Operators in ColdFusion 8</a>. Now we'll concentrate on Assignment operators.

An assignment operator assigns a value to its left operand based on the value of its right operand.

The basic assignment operator is equal (=), which assigns the value of its right operand to its left operand. That is, x = y assigns the value of y to x. The other assignment operators are usually shorthand for standard operations, as shown in the following table.]]></description>
			<content:encoded><![CDATA[<p>In my first post in this series, I introduced <a href="/using-javascript-arithmetic-operators-in-coldfusion-8" title="Using JavaScript Arithmetic Operators in ColdFusion 8">Using JavaScript Arithmetic Operators in ColdFusion 8</a>. Now we&#8217;ll concentrate on Assignment operators.</p>
<p>An assignment operator assigns a value to its left operand based on the value of its right operand.</p>
<p>The basic assignment operator is equal (=), which assigns the value of its right operand to its left operand. That is, x = y assigns the value of y to x. The other assignment operators are usually shorthand for standard operations, as shown in the following table.</p>
<table>
<tbody>
<tr>
<th>Operator</th>
<th>Shorthand operator</th>
<th>Meaning</th>
</tr>
<tr>
<td>+=</td>
<td><code>x += y</code></td>
<td><code>x = x + y</code></td>
</tr>
<tr>
<td>-=</td>
<td><code>x -= y</code></td>
<td><code>x = x - y</code></td>
</tr>
<tr>
<td>*=</td>
<td><code>x *= y</code></td>
<td><code>x = x * y</code></td>
</tr>
<tr>
<td>/=</td>
<td><code>x /= y</code></td>
<td><code>x = x / y</code></td>
</tr>
<tr>
<td>%=</td>
<td><code>x %= y</code></td>
<td><code>x = x % y</code></td>
</tr>
</tbody>
</table>
<p>In unusual situations, the assignment operator is not identical to the Meaning expression in the above table. When the left operand of an assignment operator itself contains an assignment operator, the left operand is evaluated only once. For example:</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #000099;"><span style="color: #800000;">&lt;cfscript&gt;</span></span>
<span style="color: #000099;">a<span style="color: #000000;">&#91;</span>i<span style="color: #0000ff;">++</span><span style="color: #000000;">&#93;</span> <span style="color: #0000ff;">+</span><span style="color: #0000ff">=</span> <span style="color: #ff0000;">5</span> <span style="color: #808080;">//i is evaluated only once</span></span>
<span style="color: #000099;">a<span style="color: #000000;">&#91;</span>i<span style="color: #0000ff;">++</span><span style="color: #000000;">&#93;</span> <span style="color: #0000ff">=</span> a<span style="color: #000000;">&#91;</span>i<span style="color: #0000ff;">++</span><span style="color: #000000;">&#93;</span> <span style="color: #0000ff;">+</span> <span style="color: #ff0000;">5</span> <span style="color: #808080;">//i is evaluated twice</span></span>
<span style="color: #000099;"><span style="color: #800000;">&lt;/cfscript&gt;</span></span></pre></div></div>

<p><script type="text/javascript"><!--
google_ad_client = "pub-6475233631580417";
/* 468x60 Basic */
google_ad_slot = "7117418273";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
]]></content:encoded>
			<wfw:commentRss>http://www.simonwhatley.co.uk/using-javascript-assignment-operators-in-coldfusion-8/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using JavaScript Arithmetic Operators in ColdFusion 8</title>
		<link>http://www.simonwhatley.co.uk/using-javascript-arithmetic-operators-in-coldfusion-8</link>
		<comments>http://www.simonwhatley.co.uk/using-javascript-arithmetic-operators-in-coldfusion-8#comments</comments>
		<pubDate>Mon, 25 Feb 2008 09:04:54 +0000</pubDate>
		<dc:creator>Simon</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[addition]]></category>
		<category><![CDATA[arithmetic]]></category>
		<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[decrement]]></category>
		<category><![CDATA[division]]></category>
		<category><![CDATA[examples]]></category>
		<category><![CDATA[increment]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[literals]]></category>
		<category><![CDATA[modulus]]></category>
		<category><![CDATA[multiplication]]></category>
		<category><![CDATA[operators]]></category>
		<category><![CDATA[subtraction]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[variables]]></category>

		<guid isPermaLink="false">http://www.simonwhatley.co.uk/?p=430</guid>
		<description><![CDATA[An often mentioned complaint by ColdFusion developers is the lack of operators commonly found in other programming languages such as JavaScript. For example, instead of the greater-than (<code>></code>) symbol we have been restricted to the more wordy <code>GT</code> or <code>GREATER THAN</code> operator. However, in ColdFusion 8 this has changed and we have more freedom to use familiar JavaScript operators in <code><cfscript></code> blocks.

In the following series of posts, I will introduce the changes and show some simple examples. The first in the series is Arithmetic Operators.

Arithmetic operators take numerical values (either literals or variables) as their operands and return a single numerical value. The standard arithmetic operators are addition (+), subtraction (-), multiplication (*), and division (/).

These operators work as they do in most other programming languages.]]></description>
			<content:encoded><![CDATA[<p>An often mentioned complaint by ColdFusion developers is the lack of operators commonly found in other programming languages such as JavaScript. For example, instead of the greater-than (<code>&gt;</code>) symbol we have been restricted to the more wordy <code>GT</code> or <code>GREATER THAN</code> operator. However, in ColdFusion 8 this has changed and we have more freedom to use familiar JavaScript operators in <code>&lt;cfscript&gt;</code> blocks.</p>
<p>In the following series of posts, I will introduce the changes and show some simple examples. The first in the series is Arithmetic Operators.</p>
<p>Arithmetic operators take numerical values (either literals or variables) as their operands and return a single numerical value. The standard arithmetic operators are addition (+), subtraction (-), multiplication (*), and division (/). These haven&#8217;t changed from ColdFusion version 7 to 8.</p>
<p>A key change comes with the use of <a href="http://en.wikipedia.org/wiki/Unary_operator" title="Unary Operators" rel="nofollow">Unary Operators</a>. The unary operators require only one operand; they perform various operations such as incrementing/decrementing a value by one, negating an expression, or inverting the value of a boolean.</p>
<p>These operators work as they do in most other programming languages.</p>
<p><strong>% (Modulus)</strong></p>
<p>The modulus operator is used as follows:</p>
<p><code>var1 % var2</code></p>
<p>The modulus operator returns the first operand modulo the second operand, that is, var1 modulo var2, in the preceding statement, where var1 and var2 are variables. The modulo function is the integer remainder of dividing var1 by var2. For example, 12 % 5 returns 2.</p>
<p>In ColdFusion this is written:</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #800000;">&lt;cfif</span> myQuery.currentRow % <span style="color: #ff0000;">2</span><span style="color: #0000ff;">&gt;&lt;/</span>cfif<span style="color: #0000ff;">&gt;</span></span></pre></div></div>

<p>A good use of the modulus operator would be to alternate row colours in tabular data. The above code could be wrapped around a <acronym title="Cascading Style Sheet">CSS</acronym> class, dynamically changing the name of the class on each row iteration.</p>
<p><strong>++ (Increment)</strong></p>
<p>The increment operator is used as follows:</p>
<p><code>var++ or ++var</code></p>
<p>This operator increments (adds one to) its operand and returns a value. If used postfix, with operator after operand (for example, x++), then it returns the value before incrementing. If used prefix with operator before operand (for example, ++x), then it returns the value after incrementing.</p>
<p>For example, if x is 10, then the statement y = x++ sets y to 10 and increments x to 11. If x is 10, then the statement y = ++x increments x to 11 and sets y to 11.</p>
<p>In ColdFusion, a simple example:</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #800000;">&lt;cfset</span> <span style="color: #0000ff">x</span> <span style="color: #0000ff">=</span> <span style="color: #ff0000;">10</span> <span style="color: #0000ff;">/</span><span style="color: #800000;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #800000;">&lt;cfset</span> <span style="color: #0000ff">y</span> <span style="color: #0000ff">=</span> <span style="color: #0000ff">x</span><span style="color: #0000ff;">++</span> <span style="color: #0000ff;">/</span><span style="color: #800000;">&gt;</span></span>
&nbsp;
<span style="color: #333333;"><span style="color: #800000;">&lt;cfdump</span> <span style="color: #0000ff;">var</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;#variables#&quot;</span> <span style="color: #0000ff;">label</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;Increment Operator Test 1&quot;</span> <span style="color: #0000ff;">/</span><span style="color: #800000;">&gt;</span></span></pre></div></div>

<p>The above code returns:</p>
<p><img src='http://www.simonwhatley.co.uk/blog/wp-content/uploads/2008/02/increment-operator-test-1.png' alt='Increment Operator Test 1' /></p>
<p>Switching the order of the operator to be before the variable:</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #800000;">&lt;cfset</span> <span style="color: #0000ff">x</span> <span style="color: #0000ff">=</span> <span style="color: #ff0000;">10</span> <span style="color: #0000ff;">/</span><span style="color: #800000;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #800000;">&lt;cfset</span> <span style="color: #0000ff">y</span> <span style="color: #0000ff">=</span> <span style="color: #0000ff;">++</span><span style="color: #0000ff">x</span> <span style="color: #0000ff;">/</span><span style="color: #800000;">&gt;</span></span>
&nbsp;
<span style="color: #333333;"><span style="color: #800000;">&lt;cfdump</span> <span style="color: #0000ff;">var</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;#variables#&quot;</span> <span style="color: #0000ff;">label</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;Increment Operator Test 2&quot;</span> <span style="color: #0000ff;">/</span><span style="color: #800000;">&gt;</span></span></pre></div></div>

<p>The above code returns; note that both variables return 11:</p>
<p><img src='http://www.simonwhatley.co.uk/blog/wp-content/uploads/2008/02/increment-operator-test-2.png' alt='Increment Operator Test 2' /></p>
<p><strong><code>--</code> (Decrement)</strong></p>
<p>The decrement operator is used as follows:</p>
<p><code>var-- or --var</code></p>
<p>This operator decrements (subtracts one from) its operand and returns a value. If used postfix (for example, x&#8211;), then it returns the value before decrementing. If used prefix (for example, &#8211;x), then it returns the value after decrementing.</p>
<p>For example, if x is three, then the statement y = x&#8211; sets y to 3 and decrements x to 2. If x is 3, then the statement y = &#8211;x decrements x to 2 and sets y to 2.</p>
<p>In ColdFusion, a slightly more complex example:</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #000099;"><span style="color: #800000;">&lt;cfscript&gt;</span></span>
<span style="color: #000099;"><span style="color: #808080;">//decrement the variable y</span></span>
<span style="color: #000099;"><span style="color: #0000ff;">for</span><span style="color: #000000;">&#40;</span><span style="color: #0000ff">y</span><span style="color: #0000ff;">=</span><span style="color: #ff0000;">5</span>; <span style="color: #0000ff">y</span> <span style="color: #800000;">&gt;</span> <span style="color: #ff0000;">0</span>; y<span style="color: #0000ff;">--</span><span style="color: #000000;">&#41;</span></span>
<span style="color: #000099;"><span style="color: #000000;">&#123;</span></span>
<span style="color: #000099;">	<span style="color: #800080;">writeOutput</span><span style="color: #000000;">&#40;</span><span style="color: #0000ff">y</span><span style="color: #000000;">&#41;</span>;</span>
<span style="color: #000099;"><span style="color: #000000;">&#125;</span></span>
<span style="color: #000099;"><span style="color: #808080;">//returns 54321</span></span>
<span style="color: #000099;"><span style="color: #800000;">&lt;/cfscript&gt;</span></span></pre></div></div>

<p>The above code loops from 5 to 1, decrementing the value of <code>y</code> by 1 on each iteration. The returned output is therefore 54321.</p>
<p>We could now combine the increment and decrement operators to do even more complex operations. E.g.:</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #000099;"><span style="color: #800000;">&lt;cfscript&gt;</span></span>
<span style="color: #000099;"><span style="color: #808080;">//create a new array</span></span>
<span style="color: #000099;">arrTemp <span style="color: #0000ff">=</span> <span style="color: #800080;">arrayNew</span><span style="color: #000000;">&#40;</span><span style="color: #ff0000;">1</span><span style="color: #000000;">&#41;</span>;</span>
<span style="color: #000099;"><span style="color: #808080;">//create a new variable for the array counter</span></span>
<span style="color: #000099;"><span style="color: #0000ff">x</span> <span style="color: #0000ff">=</span> <span style="color: #ff0000;">1</span>;</span>
<span style="color: #000099;"><span style="color: #808080;">//loop y, decrement the variable y</span></span>
<span style="color: #000099;"><span style="color: #0000ff;">for</span><span style="color: #000000;">&#40;</span><span style="color: #0000ff">y</span><span style="color: #0000ff;">=</span><span style="color: #ff0000;">5</span>; <span style="color: #0000ff">y</span> <span style="color: #800000;">&gt;</span> <span style="color: #ff0000;">0</span>; y<span style="color: #0000ff;">--</span><span style="color: #000000;">&#41;</span></span>
<span style="color: #000099;"><span style="color: #000000;">&#123;</span></span>
<span style="color: #000099;">	arrTemp<span style="color: #000000;">&#91;</span><span style="color: #0000ff">x</span><span style="color: #0000ff;">++</span><span style="color: #000000;">&#93;</span> <span style="color: #0000ff">=</span> <span style="color: #0000ff">y</span>;</span>
<span style="color: #000099;"><span style="color: #000000;">&#125;</span></span>
<span style="color: #000099;"><span style="color: #800000;">&lt;/cfscript&gt;</span></span>
&nbsp;
<span style="color: #333333;"><span style="color: #800000;">&lt;cfdump</span> <span style="color: #0000ff;">var</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;#arrTemp#&quot;</span> <span style="color: #0000ff;">label</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;Combined Increment Decrement Operator Test&quot;</span> <span style="color: #0000ff;">/</span><span style="color: #800000;">&gt;</span></span></pre></div></div>

<p>The above code loops from 5 to 1, decrementing the value of <code>y</code> by 1 on each iteration. At the same time, the value of <code>x</code> increments by 1 on each iteration and is used to define the array index, i.e. <code>arrTemp[1]</code>.</p>
<p>The returned output can be displayed as follows:</p>
<p><img src='http://www.simonwhatley.co.uk/blog/wp-content/uploads/2008/02/combined-operator-test.png' alt='Combined Increment Decrement Operator Test' /></p>
<p>Such code serves to demonstrate how you can set up complex operations without the need to use the following, antiquated operations:</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #800000;">&lt;cfset</span> <span style="color: #0000ff">x</span> <span style="color: #0000ff">=</span> <span style="color: #800080;">incrementValue</span><span style="color: #000000;">&#40;</span><span style="color: #0000ff">x</span><span style="color: #000000;">&#41;</span> <span style="color: #0000ff;">/</span><span style="color: #800000;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #800000;">&lt;cfset</span> <span style="color: #0000ff">y</span> <span style="color: #0000ff">=</span> <span style="color: #0000ff">y</span><span style="color: #0000ff;">+</span><span style="color: #ff0000;">1</span> <span style="color: #0000ff;">/</span><span style="color: #800000;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #800000;">&lt;cfset</span> a <span style="color: #0000ff">=</span> <span style="color: #800080;">decrementValue</span><span style="color: #000000;">&#40;</span>a<span style="color: #000000;">&#41;</span> <span style="color: #0000ff;">/</span><span style="color: #800000;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #800000;">&lt;cfset</span> b <span style="color: #0000ff">=</span> b<span style="color: #0000ff;">-</span><span style="color: #ff0000;">1</span> <span style="color: #0000ff;">/</span><span style="color: #800000;">&gt;</span></span></pre></div></div>

<p><strong>- (Unary Negation)</strong></p>
<p>The unary negation operator precedes its operand and negates it. For example, y = -x negates the value of x and assigns that to y; that is, if x were 3, y would get the value -3 and x would retain the value 3. This is not new to ColdFusion 8, but it is worth a mention.</p>
<p>In ColdFusion, this can be shown by the following:</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #800000;">&lt;cfset</span> <span style="color: #0000ff">x</span> <span style="color: #0000ff">=</span> <span style="color: #ff0000;">3</span> <span style="color: #0000ff;">/</span><span style="color: #800000;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #800000;">&lt;cfset</span> <span style="color: #0000ff">y</span> <span style="color: #0000ff">=</span> <span style="color: #0000ff;">-</span><span style="color: #0000ff">x</span> <span style="color: #0000ff;">/</span><span style="color: #800000;">&gt;</span></span>
&nbsp;
<span style="color: #333333;"><span style="color: #800000;">&lt;cfdump</span> <span style="color: #0000ff;">var</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;#variables#&quot;</span> <span style="color: #0000ff;">label</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;Unary Operator Test&quot;</span> <span style="color: #0000ff;">/</span><span style="color: #800000;">&gt;</span></span></pre></div></div>

<p>The above code returns:</p>
<p><img src='http://www.simonwhatley.co.uk/blog/wp-content/uploads/2008/02/unary-operator-test.png' alt='Unary Operator Test' /></p>
<p><script type="text/javascript"><!--
google_ad_client = "pub-6475233631580417";
/* 468x60 Basic */
google_ad_slot = "7117418273";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
]]></content:encoded>
			<wfw:commentRss>http://www.simonwhatley.co.uk/using-javascript-arithmetic-operators-in-coldfusion-8/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

