switch(true) with dynamic cases in coldfusion?

In short: no. The case value needs to be something that can be compiled to a constant value. 1==1 can be, as it's just true. foo == 1 cannot be, as foo is only available at runtime.

basically what you're describing is an if / else if / else construct anyhow, so just use one of those.


As Adam and Leigh pointed out, the case values need to be some constant. I'm not sure what your actual use case is but you can do something like this:

switch(foo){
    case 1:
        writeOutput('foo is 1');
    break;
    case 2:
        writeOutput('foo is 2');
    break;
    case 3:
        writeOutput('foo is 3');
    break;
    case 4:
    case 5:
    case 6:
        writeOutput('foo is 4 or 5 or 6');
    break;
    default: 
        writeOutput("I do not have a case to handle this value: #foo#");
}