LabVIEW Idea Exchange

cancel
Showing results for 
Search instead for 
Did you mean: 
0 Kudos
slipstick

Create a While-Loop Option or Template

Status: Declined

Where I work the Conditional Terminal in a For-Loop is frowned on. Don't ask why. It is preferred that a While Loop is used, with an Array Size that is tied to the Loop Counter. If the desired result isn't found in the loop, then the iteration count equals or exceeds the Array Size value and the loop stops. Since this functionality is desired many times when the While Loop is used anyway, why not have a way to configure the While Loop to optionally include the code to do this, and save the time to wire it in every time?

 

 

10 Comments
SteenSchmidt
Trusted Enthusiast

Time to use the proper function instead of making the wrong one do your bidding. The For-loop with a conditional terminal is the way to go, "don't ask me why" just doesn't cut it when it covers up stupidity. Alternatively make your own archaic While-loop template, stuff it in the function palette, and configure it to drop its code instead of a subVI when dragged to your block diagram. Cheers, Steen

CLA, CTA, CLED & LabVIEW Champion
slipstick
Member

Sorry, not my rule. I have to code the way I'm told. Good thought though, to add it to the function palette. 

tst
Knight of NI Knight of NI
Knight of NI

It should also be pointed out that your current implementation is missing some functionality (at least compared to the for loop) - if the array is empty, the for loop will run 0 times, whereas the while loop will run once. To have the same behavior, you would need to wrap the loop in a case structure (which, admittedly, might not be the way you want it to behave).


___________________
Try to take over the world!
AristosQueue (NI)
NI Employee (retired)

Sorry, slipstick... this is a bad idea. The For Loop with conditional is capable of a number of interesting compiler optimizations that a While Loop can't by virutue of the While Loop not knowing the upperbound on iterations. Doing what you're asking for is just making a For Loop with a thick gray border.

 

The reasons for avoiding the For Loop with break would be interesting to hear... either there's a misconception about LV that our documentation could be made to clarify or there's a use case that's being missed in our current product which we could rectify. Knowing the root problem would let us brainstorm a better solution than the one you've proposed.

Mark_Yedinak
Trusted Enthusiast

Or this is a good opportunity to educate those around you and make a positive change to your coding standards. Coding standards are great as long as they are good. Adhering to bad ones simply perpetuates the problem.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
SteveChandler
Trusted Enthusiast

And slipstick, if you do ask why (probably better to just do what you are told) make sure you mention who this Aristos Queue guy is.

 

I too would like to know what if any danger there is to using the conditional terminal in a for loop. I use it regularly and have not run into any issues.

=====================
LabVIEW 2012


Mark_Yedinak
Trusted Enthusiast

Of course the For loop with a conditional terminal should not replace all uses of a While loop. Both serve their purposes and both can be abused.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
slipstick
Member

Last time I used it and it was criticized, I came away with the impression that it was a personal preference on the part of the guy in charge. I will explore to find out more about it. Might be a few days.

RavensFan
Knight of NI

The only logical reason I can think of for not using the conditional for loop is a requirement that the code be made backward compatible easily to a LabVIEW version where the conditional For Loop didn't exist yet.  But if you are going to write code for an older LV version, then you should probably not be using a newer LV version to do so.

JordanG
NI Employee (retired)
Status changed to: Declined