I'm dealing with quite a lot of cases in my switch() statements and was wondering if there's any possible way I could shorten these. They take up a lot of space in my code and it's harder to navigate when there are 3-4 big chunks of these statements. Here's an example:
...important lines of code...
void foo(string bar, bool blam) {
int v1 = stoi(bar);
switch (v1) {
case(11):
if(blam) {
exArr[1] = "A";
} else {
exArr[1] = "B";
}
break;
case(12):
if(blam) {
exArr[3] = "A";
} else {
exArr[3] = "B";
}
break;
...many more cases...
default:
printElement();
break;
}
...even more important code, which is dependent on the hard code above and hard to navigate...
I think you see the problem. Do you guys have any suggestions? Thanks in advance.
IMPORTANT EDIT:
Only the first 12 iterations change the characters of exArr. After that, it changes to another (existing) array, like ndArr, which takes another 12 iterations. This goes on for 4 arrays, so about 48 case statements.