Pages: [1]   Go Down
Author Topic: what is permitted in a switch case?  (Read 489 times)
0 Members and 1 Guest are viewing this topic.
Cape Town South Africa
Offline Offline
Edison Member
*
Karma: 19
Posts: 1217
A newbie with loads of posts, and still so much to learn !
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

  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:
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:
Logged

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

Mountain View, CA
Offline Offline
Newbie
*
Karma: 0
Posts: 20
Professional C/C++ programmer available for projects
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Mountain View, CA
Offline Offline
Newbie
*
Karma: 0
Posts: 20
Professional C/C++ programmer available for projects
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

This is wrong:

Code:
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:
for ( int n =0; n<=3; n++ ){

Logged

Cape Town South Africa
Offline Offline
Edison Member
*
Karma: 19
Posts: 1217
A newbie with loads of posts, and still so much to learn !
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Thanks a lot
Logged

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

Mountain View, CA
Offline Offline
Newbie
*
Karma: 0
Posts: 20
Professional C/C++ programmer available for projects
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Glad to help.  Cheers.
Logged

Cape Town South Africa
Offline Offline
Edison Member
*
Karma: 19
Posts: 1217
A newbie with loads of posts, and still so much to learn !
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset



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

It now works of course....  what a great forum !
Logged

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

Pages: [1]   Go Up
Jump to: