Question

I am running into a situation where my program can have different outcomes depending on the state of some variables. 4 variables are involved and they can all have different ( 3 to 4 different states). All the possible combinations are leading me to about 48 different cases which would be resolved using a 4 level deep nested if/else structure. So, I have a couple of questions,

  1. Is there a better technique to draw logic or decision tables or some other structure so that you can model a decision tree for this many outcomes? When a decision is dependent on only 2 variables you can easily model this on a spreadsheet which is two dimensional by its nature but how do you deal with a case like the one I mentioned?

  2. Other than a 4 level deep nested if/else structure is there a better programming technique to deal with this?

Was it helpful?

Solution

I think what you're looking for is a 'decision table'

decision table example

it's tedious to fill it out, but it forces you to consider all possibilities - and you may see patterns in the variable values and/or outputs that will let you write more compact if-logic

Licensed under: CC-BY-SA with attribution
scroll top