It's a bit more advanced but in the end cleaner so I'll suggest neither and instead use an array of function pointers to individual handlers per command.
So for example:
#define MIN_CMD 0
#define MAX_CMD 2 //2 for this example
typedef void (* CommandHandler)(int);
CommandHandler Commands[MAX_CMD+1] = {&Command0, &Command1, &Command2};
In the above, CommandHandler is a type defined as being a pointer to a function that returns void and accepts an integer parameter input.
Commands[] is an array of type CommandHandler (i.e. an array of function pointers); Commands[0] points to a command handler called when command '0' is received. Commands[1] points to a function you'd want called for command '1' etc. You'd create each handler like this:
void Command0( int parameter )
{
//do stuff for command '0' here
}//Command0
void Command1( int parameter )
{
//do stuff for command '1' here
}//Command1
void Command2( int parameter )
{
//do stuff for command '2' here
}//Command2
You code would look at the command received, verify it's valid (i.e. recognized) and then call a function from the pointer array:
void loop()
{
.
.
.
if( ReceivedCommand >= MIN_CMD && ReceivedCommand <= MAX_CMD )
{
Commands[ReceivedCommand](Parm);
}//if
else
{
//command not recognized; warn user etc...
}//else
}//loop
Here's a working example framework I just ran a MKR WiFi 1010 I had lying around (should be fine on whatever you're using...)
#define MIN_CMD 0
#define MAX_CMD 2
typedef void (* CommandHandler)(int);
//prototypes
void Command0( int parm );
void Command1( int parm );
void Command2( int parm );
CommandHandler Commands[MAX_CMD+1] =
{
&Command0,
&Command1,
&Command2
};
void setup()
{
// put your setup code here, to run once:
Serial.begin(9600);
while( !Serial );
}//setup
void loop()
{
ProcessCommand(0, 1);
ProcessCommand(1, 465);
ProcessCommand(2, 1000);
ProcessCommand(4, 0); //should generate an unrecognized command error
delay(1000);
}//loop
void ProcessCommand( int Cmd, int Parm )
{
if( Cmd < MIN_CMD || Cmd > MAX_CMD )
{
Serial.println( "*** ERROR Unrecognzied command ***" );
}//if
else
{
Commands[Cmd](Parm);
}//else
}//ProcessCommand
//Command handlers
void Command0( int parm )
{
Serial.print( "Command 0: " );
Serial.println (parm );
}//Command0
void Command1( int parm )
{
Serial.print( "Command 1: " );
Serial.println (parm );
}//Command1
void Command2( int parm )
{
Serial.print( "Command 2: " );
Serial.println (parm );
}//Command2
I think this would generate the cleanest and probably pretty quick code.