Using Switch in Calculations

Hi Folks, I’ve probably screwed up the syntax for my switch, but I cant understand why similar formatting on switch and If() react differently? Using:

if (vRiskFactorTotal > 0 && vRiskFactorTotal < 166) {return 6;}
if (vRiskFactorTotal > 166 && vRiskFactorTotal <= 332) {return 5;} I get my expected return, but with:

switch(vRiskFactorTotal){
case ‘> 0 && < 166’:
return 6;
break
case ‘> 166 && <= 332’:
return 5;
break

it simply does’nt calculate (or return the value). I’m assuming that Switch is supported in stored calculations!

Appreciate Feedback.

Hi Ian,

The syntax for switch is the following:

switch (expression) {
case value1: 
  statement;
  break;
case value2: 
  statement;
  break;
default : 
   statement;
}

So your ‘> 0 && < 166’ is considered a value, not an expression.
That’s the reason why it doesn’t work as you want.

Ahh… I see that Robert - thanks for pointing it out.