<CFSCRIPT> Part 2 Using if and else statements in flow control
Submitted by tigersam on Fri, 2006-01-06 16:19.
For simple flow control you could use <CFSCRIPT> along with the if and else keywords. Here is an example:
<CFSCRIPT>
first_name = "Sam";
if(#first_name# eq "Sam") {
WriteOutput("Hello #first_name#");
} else {
WriteOutput("Hello Stranger!");
}
</CFSCRIPT>
Here's the explanation:
Set the value of the variable first_name to "Sam". Following "if", the condition is enclosed in parentheses. Each line of code end with the semicolon (;). If the condition inside the parentheses is met, the code inside the curly braces is executed.
The if-else statements only provide for two choices. If you need more, you will need to use the switch-case statements. I'll show you examples of these in the next post.

Recent comments
1 year 20 weeks ago
2 years 42 weeks ago
3 years 15 weeks ago
3 years 15 weeks ago
3 years 19 weeks ago
3 years 20 weeks ago
3 years 20 weeks ago
3 years 22 weeks ago
3 years 35 weeks ago
3 years 35 weeks ago