02-09-2012 11:49 AM
Hello All,
In debugging some code, written by someone else, I found a construct, a For Loop containing a Switch, with the For Loop Index driving the Switch through all the Cases.
Why would that be used instead of a Stacked Sequence or Flat Sequence?
Can you think of any reason?
Thanks,
-Drewski
02-09-2012 11:52 AM - edited 02-09-2012 11:53 AM
You can programmatically exit the For loop (in newer LV versions) in the middle of it. You can't do that with a sequence. I'm more accustomed to seeing it in a While loop.
02-09-2012 11:58 AM
Okay, I can see how that would be useful, however in this situation, there isn't a premature exit coded into the construct. The construct is used to initialize fields in a record, so no reason to exit.
02-09-2012 12:13 PM
I'm doing that exact thing in one of my projects. Why? Its simple... Each frame has enough code to warrant it and I dont like sequence structures. Especially stacked sequences. If I need to pass data between the frames, then there are the trusty shift registers.
02-09-2012 12:13 PM
That sounds like someone trying to create a state machine, but not completely understanding the concept. Or perhaps the programmer had read about how sequence frames are "evil" (which they are not, if used correctly), and decided to do it that way instead.
02-09-2012 12:15 PM
It boils down to a matter of personal preference I guess.
02-09-2012 12:22 PM
> pass data with shift registers
Okay, and if a flat sequence was used, all the code would be visable and you could pass data from frame to frame?
I also decided it might be a timing issue, with a delay between each cases set parallel with the switch, however no delay code found??
02-09-2012 12:23 PM
@WayneS1324 wrote:
I'm doing that exact thing in one of my projects. Why? Its simple... Each frame has enough code to warrant it and I dont like sequence structures. Especially stacked sequences. If I need to pass data between the frames, then there are the trusty shift registers.
I have done this as well, so it's a pretty reasonable guess as to a possible reason.
02-09-2012 12:26 PM
Another variation of Jim's idea depends on if the For Loop has an auto-indexing tunnel. Pass it an empty array it does nothing, an array with four elements, it does the first four things.
Ben
02-09-2012 12:31 PM
@Drewski wrote:
> pass data with shift registers
Okay, and if a flat sequence was used, all the code would be visable and you could pass data from frame to frame?
I also decided it might be a timing issue, with a delay between each cases set parallel with the switch, however no delay code found??
You could. But if there's a lot of code then you may end up with a massive sequence structure (with all of the frames beside one another).