|
Author |
Topic: case / switch (Read 368 times) |
|
st33d
|
case / switch
« on: Feb 22nd, 2005, 11:58pm » |
|
I can't seem to get case and switch working. They seem to have an odd attitude towards newlines. I've seen people use a case statement to execute more than one command at a time so how would I get it to do the following code properly with out just executing every line? Code: switch(con){ case 0: strokeWeight(3); point(ix-(xm/2),iy-(ym/2),c1-(zm/2)); case 1: line(ix-(xm/2),iy-(ym/2),c1-(zm/2), ix-(xm/2)+1,iy-(ym/2),c2-(zm/2)); case 2: line(ix-(xm/2),iy-(ym/2),c1-(zm/2), ix-(xm/2)+1,iy-(ym/2),c2-(zm/2)); line(ix-(xm/2),iy-(ym/2),c1-(zm/2), ix-(xm/2),iy-(ym/2)+1,c3-(zm/2)); case 3: noStroke(); if (col){ fill(video.pixels[ix + iy*xm]); }else{ fill(grey(video.pixels[ix + iy*xm])); } beginShape(QUADS); //texture(video); vertex(ix-(xm/2),iy-(ym/2),c1-(zm/2));//,xm/ix,ym/iy); vertex((ix+1)-(xm/2),iy-(ym/2),c2-(zm/2));//,xm/ix,ym/iy); vertex((ix+1)-(xm/2),(iy+1)-(ym/2),c4-(zm/2));//,xm/ix,ym/iy); vertex(ix-(xm/2),(iy+1)-(ym/2),c3-(zm/2));//,xm/ix,ym/iy); endShape(); } |
|
|
I could murder a pint.
|
|
|
JohnG
|
Re: case / switch
« Reply #1 on: Feb 23rd, 2005, 12:28am » |
|
I think you probably need to put a "break;" in all of those cases, or it'll chain through the whole lot. e.g. Code:switch(i) { case(0): x++; y--; break; case(1): x--; y++; break; } |
| without a break, the code will just start fomr the first matching case(), through the code. I think it works like this (in most languages) for historical reasons (there's some funky loop unrolling you can do with cases falling through to the next part etc, but it's all archaic nowadays.)
|
|
|
|
st33d
|
Re: case / switch
« Reply #2 on: Feb 23rd, 2005, 12:25pm » |
|
That works, thanks.
|
I could murder a pint.
|
|
|
|