If the values of options.test
are either 1 or 2 throughout the execution of your program, then you can simply do:
options.test = 3-options.test;
If this variable may be set to other values, then the best way to handle it is usually with:
switch (options.test)
{
case 1: options.test = 2; break;
case 2: options.test = 1; break;
case ...: options.test = ...; break;
case ...: options.test = ...; break;
case ...: options.test = ...; break;
default: options.test = ...; break;
}
If the values are between 0 and N (with a relatively small N), then you may also consider hashing.
For example, instead of:
switch (options.test)
{
case 0: options.test = 4; break;
case 1: options.test = 2; break;
case 2: options.test = 1; break;
case 3: options.test = 3; break;
case 4: options.test = 5; break;
case 5: options.test = 0; break;
}
You can do:
static int hash[] = {4,2,1,3,5,0};
options.test = hash[options.test];