solved: simple loop logic quesiton

I have a simple question about loop. see codes. when SC=10, then SC-1=9, then stLED[9]=0 should go LOW. but it's not the case here. I have to write this line "stLED[9]=0;" to get stLED[9] low. what is the problem here?

this works

if(SC==10){ 
SC=0;
stLED[9]=0;}

stLED[SC-1]=0;
stLED[SC]=1;

this doesn't work

if(SC==10){ 
SC=0;
}

stLED[SC-1]=0;
stLED[SC]=1;

what is the problem here?
when SC=10, then SC-1=9, then stLED[9]=0 should go LOW

SC never has a chance to be decremented to 9, you set it to zero then subtract one:

if(SC==10){
SC=0;
stLED[9]=0;}

stLED[SC-1]=0;
stLED[SC]=1;

pYro_65:

what is the problem here?
when SC=10, then SC-1=9, then stLED[9]=0 should go LOW

SC never has a chance to be decremented to 9, you set it to zero then subtract one:

if(SC==10){
SC=0;
stLED[9]=0;}

stLED[SC-1]=0;
stLED[SC]=1;

I see. thanks, it works like this.

if(mode==0){
stLED[SC-1]=0;

if(SC==10){ 
SC=0;
}

stLED[SC]=1;

If you ever set SC to zero then SC-1 is not a valid array index. Even if you don't see any symptoms yet, it's likely that this is corrupting memory and not working as you think.

PeterH:
If you ever set SC to zero then SC-1 is not a valid array index. Even if you don't see any symptoms yet, it's likely that this is corrupting memory and not working as you think.

will this corrupting memory damage my naon board in long term?

No, it just screws up what is stored in SRAM so your sketch does funny things; some other variable is getting its stored value bushwhacked.

CrossRoads:
No, it just screws up what is stored in SRAM so your sketch does funny things; some other variable is getting its stored value bushwhacked.

I see, so it is something I need to fix. even it has not giving me an error yet.