ColdFusion If Statements

A conditional statement is a piece of code that does one thing based on one condition, and another based on another condition. In fact, you could have as many conditions as you like.

ColdFusion If statements are an example of conditional statements. With If statements, you can tell the ColdFusion server to execute a piece of code only if a given condition is true.

Example If Statement

In this example, the text "Still haven't found what I'm looking for." only gets displayed if the condition is met (that the value of the variable firstName equals Bono.

The letters eq are used with <cfif> to test that a something is equal to something.

Result
Still haven't found what I'm looking for.

"If Else" Statement

You can use the <cfelse> tag to do something if the condition is not met.

Result
Choose your own song then...

Example "If Else If" Statement

You can use the <cfelseif> tag to perform another test (only if the preceeding condition/s is/are not met).

Result
Crazy Train!

NOT Equal To?

Just as eq stands for "equal to", neq stands for "not equal to".

Result
Crazy Train!

Less Than?

You can use lt to test that a value is less than another.

Result
Don't give up your day job!

Greater Than?

You can use gt to test that a value is greater than another.

Result
Give up your day job!

Greater Than Or Equal To/Less Than Or Equal To?

You can use gte to test that a value is greater than or equal to another.

You can use lte to test that a value is less than or equal to another.

Result
Give up your day job!