One may consider using case rather than if-then-else statements. If there are different cases, then the code goes to the right choice. This will save time without going through everything.
If f_op is v_op then
If o_op == f_op then
If (o_r_type == "C" AND f_r_type == "D") OR
(o_r_type == "D" AND f_r_type == "C") OR
(o_r_type == "C" AND f_r_type == "C") then
do nothing
else if o_r_type == "D" AND f_r_type == "D" then
v_b.add(i)
else if o_op_cat == f_op_cat then
v_b.add(i)
How to modify above pseudocode and use case statements instead of if-then-else.
Assuming that the possible values of
f_r_typeando_r_typeare "C" and "D" (confirmed in comments) there are some remarks to make:when
if o_r_type == "D" AND f_r_type == "D" thenis executed, that condition will always be found to be true: all other possibilities were already excluded by the previousifcondition.Related: the longer
ifcondition (with three combination tests) tests the opposite of the nextifcondition, and so you could reduce code by only using that next condition.The very first two
ifstatements can be joined into oneifstatement.As there is only one action that is or is not performed (
v_b.add(i)), you should only need oneifstatement that combines all the conditions for it into one.Your code would do the same if it were written like this:
Here there is no gain for using a
switchstatement, as you really only have one case.