07-29-2010 09:18 AM
Hi all,
Please let me know what is the best way to tackle the simple problem below with as few case structure as possible.
input: a 1D array of 2 elements.
ideal (if possible): there would be a case structure with 3 cases plus a default case. The condition would be if element 1 or element 2 from the input satistify case 1-execute case 1, same for case 2, same for case 3, and if none of the element satisfy any case, execute the else case.
Note: I only want to run the default structure only if none of the element in the array match any of the cases.
Solved! Go to Solution.
07-29-2010 09:22 AM
Reader digest version
Use a compare if eaqual configured to compare elements and then case the boolean array as a number wired to the case structure. The cases should be configured for the possilbe values.
Maybe someone will draw this up.
Ben
07-29-2010 11:24 AM
Here is a picture of Ben's solution:
If this isn't what you are looking for, then tell us what the 3 conditions are that will cause the 3 cases to execute. Could it be like A<B or A>B or A=B, where A is the first array element and B is the second?
07-29-2010 12:08 PM
Very close to what I was thinking.
here you go.
The "0" case is the default and catches the no match.
"1" "3" catches when the first matches or both match.
"2" catches the second matchine only.
That is three cases by my count.
Ben
07-29-2010 04:26 PM
Hi all,
My situation is slightly different, but I took what you guys showed me and created the attached. Please take a look and see can I refine it some more. Thanks!
Yik
07-30-2010 07:18 AM
Using binary for the case is a nice touch.
If that logic does what you want Its OK but I did not exactly see what you are trying to match up so for the sake of those that follow you, you may want to add some text explaining your logic in plain speak.
Another thing you can add is an enum to make reading the case easier. After caseting the nimeric as a U32 (or is it I32) you can type cast the numeric as the enum. THe enum can be set up so that you have a clear way of defining the condition.
For example;
In the code I showed I set up a case to handle the values "1" and "3" in the same case. If I had type cast it as an enum where the value "3" had the text "Both match", you would not have to understand boolean to understand that case was intended to handle the condition when both values matched up.
Ben
07-30-2010 09:45 AM
The type casting is a good call.