# Need Help to Explain this Code

Hi, i am a beginner with arduino…
Yesterday i try to control servo with Visual Basic 2010 with some code that i found from:

And it works, but i still confused about the code, especially with this code:

``````switch(ch) {
case '0'...'9':
val = val * 10 + ch - '0';
``````

i have searching for the explanation on arduino websites, forum and entire internet, but still don’t get the explanation…
Can anyone help me?

And this is the complete code:

``````#include <Servo.h>

Servo myservo;

void setup() {

myservo.attach(A0);
Serial.begin(9600);
}

void loop() {

static int val = 0;

if(Serial.available())
{

switch(ch) {
case '0'...'9':
val = val * 10 + ch - '0';

break;
case 's':
myservo.write(val);
val = 0;
break;
}

}
}
``````

Thank You

Normally, you need to have a single value for a case statement, like '0'. On the Arduino, '0'...'9' is an extension that means any value from '0' to '9' triggers that case.

``````val = val * 10 + ch - '0';
``````

It isn't a formula, it is an assignment. The way you tell the difference is that whilst `x = x + 1;` makes sense to a programmer, it is clearly mathematically nonsensical - how can "x" be the same as "x + 1"?
``````val = val * 10 + ch - '0';