break / case


how make case statment act of range of numbers like.

if ( var >= 100 && var < 200 ) instead of guess 1 value .




switch (var) {
   case 1:
     //do when var == 1
     break;
     // break optional
   case 2:
     //do when var == 2
     break;
   default:
     // if nothing else matches, default
     // default optional
 }

quote
how make case statment act of range of numbers

you don't - works on discrete values only.  you'll need if-else block ranges.

the switch statement enters code block @ particular case matches, , executes remaining code in cases unless hits break.  as result of behavior, if there few values in range, can list them this:

code: [select]
switch(x)
{
 case 1:
 case 3:
 case 5:
    // code 1,3,5 case
    break;
 case 2:
 case 4:
 case 6:
    // code 2,4,6 case
    break;
 default;
}


-j



Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > break / case


arduino

Comments

Popular posts from this blog

CAN'T INSTALL MAMBELFISH 1.5 FROM DIRECTORY - Joomla! Forum - community, help and support

error: expected initializer before 'void'

CPU load monitoring using GPIO and leds - Raspberry Pi Forums