LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Why use this construct? Coding Style Issue

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

0 Kudos
Message 1 of 15
(3,292 Views)

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.

 

Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
For he does not know what will happen; So who can tell him when it will occur? Eccl. 8:7

0 Kudos
Message 2 of 15
(3,290 Views)

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.

0 Kudos
Message 3 of 15
(3,282 Views)

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.

0 Kudos
Message 4 of 15
(3,273 Views)

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.

0 Kudos
Message 5 of 15
(3,272 Views)

It boils down to a matter of personal preference I guess.

0 Kudos
Message 6 of 15
(3,269 Views)

> 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??

0 Kudos
Message 7 of 15
(3,262 Views)

@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.

0 Kudos
Message 8 of 15
(3,258 Views)

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

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 9 of 15
(3,254 Views)

@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).

0 Kudos
Message 10 of 15
(3,248 Views)