09-12-2011 12:56 PM
But how can I write two state names in one false case. Program may freeze to decide which state to run next. Can you give me some example code with your suggested idea. I did not understand quite well.
09-13-2011 04:26 AM
Hello,
Can I use many case structures inside a case structure which are in a while loop. Is that wrong in matters of efficiency.
09-13-2011 10:25 AM
Can you post as a snippet? Not everyone has LV2011 installed, yet.
Or save back to an earlier version such as 8.5 to cover more people.
09-13-2011 10:31 AM
Here you can see.
09-13-2011 10:52 AM
In general if you have multiple nested structures or several structures in a single while loop you could probably come up with a better architecture. It is not always a question of efficiency. In fact it is possible to write some very obscure code that is more efficient than a standard design pattern. But code should be designed to be read by humans. You might want to do some weird things if they are the most efficient and your VI requires that level of efficiency.
You should always put programmer efficiency ahead of program efficiency whenever you can. And by programmer I mean not only the guy writing the code. I am most concerned with the guy reading the code. Always think of his efficiency. The computer does not care one bit about your design pattern.
09-13-2011 10:57 AM
Steve beat me to a similar reply.
Yes, you can put nested Case Structures, but why??
I see it often in programs that I am called upon to fix. Those nested Case Structures (and Stacked Sequence Structures) are the first thing to go (be removed) from the block diagram. In all situations, a simplified version of the code was written.
Can you describe the logic that you are trying to implement and we'll help you avoid becoming a Rube Goldberg candidate..
http://forums.ni.com/t5/BreakPoint/Rube-Goldberg-Code/td-p/399999
09-13-2011 11:41 AM
I am just using JKI state machine concept but in some situations, I need to use case structure inside a case. So, I just wonder weather I can go in that way or not. After reading your messages, I come to know that I can do that.
09-13-2011 11:43 AM
When I have multiple conditions that need to be checked rather than nesting case structures I like to combine them into a Boolean array and convert that to a number. I use this number to select a case within a single case structure however it allows me to use fairly complex combinational logic to drive my decision.
09-13-2011 11:44 AM
@shjukheter wrote:
I am just using JKI state machine concept but in some situations, I need to use case structure inside a case. So, I just wonder weather I can go in that way or not. After reading your messages, I come to know that I can do that.
If you have case structures in your states then you might ask yourself the question "do I need to define more states". The answer may very well be no but it is worth asking.
09-13-2011 11:48 AM
A single case structure within a case is acceptable if need to chose th enext state based on some combination of conditions. Sometimes it is far more readable and maintainable to have that logic in a single case rather than getting overly complex with multiple states that are nearly identical and essentially differ only in which state they trigger next.
Now having tons of cases within cases or deep nesting is not a good thing. But there is nothing bad about ising a case structure to chose the next state.