# Using Switch in Calculations

**URL:** <https://forum.servoy.com/t/using-switch-in-calculations/10333>\
**Category:** Classic Servoy\
**Created:** [February 28, 2009, 5:08pm UTC](https://forum.servoy.com/t/using-switch-in-calculations/10333 "2009-02-28T17:08:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kahuna](https://avatars.discourse-cdn.com/v4/letter/k/8491ac/32.png) [@Kahuna](https://forum.servoy.com/u/Kahuna)\
**Post date:** [February 28, 2009, 5:08pm UTC](https://forum.servoy.com/t/using-switch-in-calculations/10333/1 "2009-02-28T17:08:36Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ROCLASI](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/roclasi/32/4371_2.png) [@ROCLASI](https://forum.servoy.com/u/ROCLASI)\
**Post date:** [February 28, 2009, 6:07pm UTC](https://forum.servoy.com/t/using-switch-in-calculations/10333/2 "2009-02-28T18:07:11Z")

</div>

Hi Ian,

The syntax for switch is the following:

```auto
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.

---

<div class="post-metadata">

**Author:** ![Kahuna](https://avatars.discourse-cdn.com/v4/letter/k/8491ac/32.png) [@Kahuna](https://forum.servoy.com/u/Kahuna)\
**Post date:** [February 28, 2009, 7:31pm UTC](https://forum.servoy.com/t/using-switch-in-calculations/10333/3 "2009-02-28T19:31:19Z")

</div>

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