I am doing something like this:
The first scenario:
for(int i=0; i<50; i++){
// execute some other code here
switch(myCustomInt){
case 1:
case 2:
case 3:
// execude method1
break;
case 4:
// execute method2
break;
}
}
The second scenario:
for(int i=0; i<50; i++){
// execute some other code here
}
switch(myCustomInt){
case 1:
case 2:
case 3:
for(int i=0; i<50; i++){
// execute method1
}
break;
case 4:
for(int i=0; i<50; i++){
// execute method2
}
break;
}
The Question:
The first scenario runs the for loop only once, but check the switch statement 50 times.
The second scenario runs the for loop twice, but check the switch statement only once.
Which is a better way to execute? I know in today's technology, the difference is most likely negligible. But I am still curious which one is, theoretically, the better way to execute it?
Thank you!