Go Down

Topic: what is permitted in a switch case? (Read 572 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:

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

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 !

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy