March 11th, 2003, 07:50 PM
if vs. switch memory
Lets say the user is given 1-10 options to be taken to a function (each number going to a different function). To see what the user typed in, would it be more efficient to use if statements or a switch to redirect them? It won't make a huge deal in this situation, but lets say the program was huge, which one would be the better call? Thanks.
March 11th, 2003, 08:37 PM
In this case I would suggest using switch
March 11th, 2003, 10:32 PM
Of course a third option is having an array of function pointers and dereferencing an index based on the user's choice (after bounds checking, of course). This can handle huge ranges of possibilities in a few lines of code.
Not sure which method is fastest, but the case structure is definitely the easiest to read...