Go Down

Topic: what is permitted in a switch case? (Read 533 times) previous topic - next topic

Boffin1

  Is it OK to run functions and for () functions inside various cases of a switch structure ?

These functions  redtens ();  zero();  and   one();   all run OK on their own, but the code just doesn't run the switch statement....  heres a bit of the code:-


Code: [Select]
break;
      case 2:
        ////////////////////////////////////   send all this 4 times with pilot and sync bit
        for ( int n =0; n>=3; n++ ){
          redtens ();  //  sends tile and customer number for red tens
          zero();
          one();
          zero();
          zero();       
          digitalWrite(dataPin, LOW );

        break;
      case 3:
With my mobile phone I can call people and talk to them -  how smart can you get ?

montecito

This code actually compiles ??? Where is the closing brace for your "for" loop.  Maybe you should post the entire routine.

montecito

This is wrong:

Code: [Select]
for ( int n =0; n>=3; n++ ){

Initializing n to 0 will cause the for-loop conditional n >= 3 to always fail and your loop will never be executed.

You probably meant:

Code: [Select]
for ( int n =0; n<=3; n++ ){


Boffin1

LOL  -   I really can't believe I did that !!    :smiley-red:

Thanks a lot
With my mobile phone I can call people and talk to them -  how smart can you get ?

montecito


Boffin1



You wont believe how many times I overlooked that while going through for ==  etc !

It now works of course....  what a great forum !
With my mobile phone I can call people and talk to them -  how smart can you get ?

Go Up