nested switch/case

void setup()
{
for (int k = 2; k <= 9; k++){
pinMode(k, OUTPUT); }

for (int k = 10; k<=12; k++){
pinMode(k, INPUT); }

Serial.begin(9600);
}

void loop()
{
int S2 = digitalRead(12);
int S1 = digitalRead(11);
int S0 = digitalRead(10);

//Reseting LEDs
delay(500);
for (int k = 2; k<=9; k++){
digitalWrite(k,LOW);}

int q = 6;
switch (S2){
case 0:
switch (S1){
case 0:
// S2=0 && S1=0
switch (S0){
case 0:
for (int k = 5; k>=2; k–){
digitalWrite(k, HIGH);
delay(500);}

case 1:
for (int k =6; k<=9; k++){
digitalWrite(k,HIGH);
delay(500);}
}
case 1:
switch(S0){
case 0:
for (int k = 5; k>=2; k–){
digitalWrite(k, HIGH);
digitalWrite(q, HIGH);
delay(500);
digitalWrite(k, LOW);
digitalWrite(q, LOW);
q++;
}

case 1:
for (int k = 2; k<=9; k++){
digitalWrite(k, HIGH);
}
delay(500);
for (int k = 2; k<=9; k++){
digitalWrite(k, LOW);
}

}
}
}
}

hey guys and girls,

So the problem I am running into is that for the case s2=0; s1=0; s0=0, the program executes as if it were 000 and immediately 010 after that. If my s2/s1/s0 are not being adjusted within the switch/cases, or within my circuit, why is it executing both branches?

Also, I altered the code during some troubleshooting to have s2=0; s1=0; and s0=0 as a declaration, and the code executes each individual case sequentially. What’s the dealio?

Switches need breaks. Can't say I've ever seen a nested switch before, maybe there is a better way. It looks difficult to read and understand.
Also please use code tags when posting on the forum.

Metallor:
Switches need breaks. Can't say I've ever seen a nested switch before, maybe there is a better way. It looks difficult to read and understand.
Also please use code tags when posting on the forum.

.....that worked! I had breaks placed appropriately before and took them out as I was troubleshooting. I suppose I missed one of them while implementing new cases and the code broke. Thank you