Hi,

I tried searching but I don't know how exactly to describe my question in 2-3 words so I didn't find anything.
Is it possible to do something like this?Just to get the idea... I know it doesn't work:

``````switch(c){
case '1':{ (...) ; break;}
case '2':{ (...) ; break;}
case '3':{ (...) ; break;}
if(f){
case '4':{ (...) ; break;}
case '5':{ (...) ; break;}
case '6':{ (...) ; break;}
}
}``````

I can always do it this way:

``````if(f){
switch(c){
case '1':{ (...) ; break;}
case '2':{ (...) ; break;}
case '3':{ (...) ; break;}
case '4':{ (...) ; break;}
case '5':{ (...) ; break;}
case '6':{ (...) ; break;}
}
}
else{
switch(c){
case '1':{ (...) ; break;}
case '2':{ (...) ; break;}
case '3':{ (...) ; break;}
}
}``````

Or put the if check in cases 4,5,6...
Isn't there anything simpler and better to do?

## All 2 Replies

``````switch(c){
case '1':{ (...) ; break;}
case '2':{ (...) ; break;}
case '3':{ (...) ; break;}
}
if(f){
switch(c){
case '4':{ (...) ; break;}
case '5':{ (...) ; break;}
case '6':{ (...) ; break;}
}
}``````

You could always take advantage of the short-circuit operators.

``````switch (argc) {
case 1: { printf("1\n"); break; }
case 2: { printf("2\n"); break; }
case 3: { printf("3\n"); break; }
case 4: { (f) && printf("4\n"); break; }
case 5: { (f) && printf("5\n"); break; }
case 6: { (f) && printf("6\n"); break; }
}``````
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.