FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Programming Questions & Help
   Syntax
(Moderators: fry, REAS)
   case(val) { }
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: case(val) { }  (Read 419 times)
Markavian

Markavian+iTX WWW
case(val) { }
« on: Apr 16th, 2004, 4:12pm »

Any plans to include the 'case() { }' syntax?
 
I found myself typing it once when dealing with keyboard inputs, then having to revert to a big sequence of if/else statements
 
case(int val) {
  1:  
  2:
  3:
    print "1 to 3";
  break;
 
  4:
  5:
  6:
    print "1 to 6";
  break;
 
  default:
    print "I have no code for that value";
}
 
I know its not everyone's favourite way of programming, but its a useful way of formatting certain types of code.
 
mohn

WWW Email
Re: case(val) { }
« Reply #1 on: Apr 16th, 2004, 4:30pm »

you should be able to work this with the switch() statement:
 
int v;
switch ( v ) {  
   case 0: s++;  
   case 1: ...
 
http://java.sun.com/docs/books/tutorial/java/nutsandbolts/switch.html
 
-mohn
 
fry


WWW
Re: case(val) { }
« Reply #2 on: Apr 16th, 2004, 5:47pm »

case 0: s++;  
should usually be:
case 0: s++; break;
otherwise all the cases will run together, fwiw
(only posting correction since someone elsewhere on the board just ran into trouble with this..)
 
mohn

WWW Email
Re: case(val) { }
« Reply #3 on: Apr 17th, 2004, 4:44am »

thank you for the correction ... 7:00am and the coffee was still a brewin...
 
Markavian

Markavian+iTX WWW
Re: switch() { }
« Reply #4 on: Apr 18th, 2004, 2:39am »

my bad, faulty memory.
 
switch(value) {
  case 1: s++; break;
  case 2: i++; break;
  default: print "lly.";
}
 
thanks all the same. I'll know for next time. (doh)
« Last Edit: Apr 18th, 2004, 2:41am by Markavian »  
Pages: 1 

« Previous topic | Next topic »