<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
6 weeks 5 days ago
6 weeks 5 days ago
10 weeks 1 day ago
10 weeks 6 days ago
10 weeks 6 days ago
13 weeks 5 hours ago
25 weeks 6 days ago
25 weeks 6 days ago
26 weeks 1 day ago
26 weeks 2 days ago