NOTE: thankyou for telling me this will save next to nothing no matter how I write it, the reason I am asking is cause it is similar of my uni assignment and I would like to make my lecturer happy, is there a more 'readable' code or something better that would make my lecturer happier or is this code fine and not 'inefficient'.
I have a question on how i should write my code, basically I have a switch statement that is used to change a char to a specific char depending on what linenumber it is on. however it only changes if the linenumber is an odd number ( starting from 0, so every 2nd line itll pick a new char). currently my code is....
int linenumber;
char zone = UNKNOWN;
for (linenumber = 0; linenumber < 21; linenumber++) {
switch (linenumber) {
case (1):
zone = 'a';
break;
case (3):
zone = 'b';
break;
case (5):
zone = 'c';
break;
case (7):
zone == 'd';
break;
case (9):
zone = 'e';
break;
case (11):
zone = 'f';
break;
case (13):
zone = 'g';
break;
case (15):
zone = 'h';
break;
case (17):
zone = 'i';
break;
case (19):
zone = 'j';
break;
if (linenumber % 2 == 0) {
}
}
}
however, since the switch only happens for every 2nd case, is it more efficient to write a if statement such as....
if (linenumber % 2 == 1) {
switch.....
}
to put the switch statement inside... just wondering if an extra if statement would be more or less efficient in this situation.
Thanks in advance!