NI Home
Cart Cart | Help
Hello Events Academic NI Developer Zone Support Solutions Products & Services Contact NI MyNI
You are here: 
NI Home > NI Developer Zone > NI Discussion Forums


Reply
Active Participant
Joe_H
Posts: 1,339
0 Kudos

Re: For Loop with Break

Just give me a for loop with a start, stop, and break and all will be well.

 




Joe.
"NOTHING IS EVER EASY"
Member
RobbieG
Posts: 23

Re: For Loop with Break

Hello all,

Thanks again to everyone who has contributed to this topic.  Now that 8.20 is out the door, I had a brainstorming meeting with other developers on this topic.  As much as I liked the idea of a Flex Loop for how easy it made a lot of very common operations--things that are easy enough to code with LabVIEW functions, but clutter up the diagram and make it harder to read--there was a lot of resistance to adding yet another structure to the Structures palette, and to the LabVIEW language in general.  For new users, this makes LabVIEW more complicated and difficult to learn.  For experienced users, it's noise...either they like the Flex Loop and use it exclusively (in which case, the For and While loops are noise), or they never want to use it and it becomes noise itself.

That doesn't mean, however, that we can't help make some of the common operations you have mentioned so far easier.  Perhaps we can add functionality to the existing For and While loops to allow for some of the things mentioned, like custom shifting/scaling of the iterator terminal and allowing more configurability to the auto-index terminals.  But at this time, we're not convinced that the use cases are common enough to make these changes worthwhile.

So, what I would like from you all is examples (preferably VIs) of when these features would be useful and would have simplified your diagram.  This way, we can discuss a solution to as general a problem as possible, hopefully making LabVIEW a more productive tool for everyone.

 

Thanks in advance,
Robbie

Active Participant
crelf
Posts: 1,343
0 Kudos

Re: For Loop with Break

I still really really really want the native wait in for and while loops!

crelf wrote:
One feature I've been asking for for years: a native wait in every loop:
 

 
 
If unwired it would default to 0, and at least let thread switching occur.  You could maybe right click on the loop and remove the wait node to make it run as fast as possible (like it is now), but it should be there by default...  (PS: I know that you can do this using timed loops, but I'd like to see it in all of them - I've seen too many "programmers" complain that their CPU is at 100% because their loops are going nuts).




Do you know about LabVIEW Advanced Virtual Architects (LAVA)?
Forums | LabVIEW Wiki | Code Repository
Copyright © 2004-2012 Christopher G. Relf. Some Rights Reserved. This posting is licensed under a Creative Commons Attribution 2.5 License.
Active Participant
JeffB_in_LV
Posts: 449
0 Kudos

Re: For Loop with Break

The wait might go a bit beyond the scope of what Robbie was going for, I'm not sure.  Just curious, why not use a timed loop?  I can think of a couple of valid reasons myself, but was just wondering what your reasons were.
Member
Jaegen
Posts: 190
0 Kudos

Re: For Loop with Break

Here's the (simple) benefit as I see it.

Rather than having to do something like this:

We can do this:

I think that just being able to do this would cover most of the times I would find this feature helpful.  All the other suggestions about start/stop/iteration/waits etc. are helpful, and I would find them useful, but in my mind they're all gravy.  Can we agree that at a minimum this is what everyone wants?  (probably not, but I can dream ...):smileyvery-happy:

My vote would be to add something like "Early Break Node" to the "Visible Items" context menu for a For Loop, and have it hidden by default when a For Loop is dropped.

Jaegen

-----------------------------------------------------------------------------------------------------------------------------------
"Duck was a neutral party, so he brought the ultimatum to the cows." -- Click, Clack, Moo: Cows That Type
Trusted Enthusiast
Albert.Geven
Posts: 3,142
0 Kudos

Re: For Loop with Break

Good simplification
greetings from the Netherlands
Trusted Enthusiast
AristosQueue
Posts: 2,430
0 Kudos

Re: For Loop with Break

I like it, but is there any way you can come up with to make this a decent pre-test loop instead of a post-test loop? The For Loop tests its loop condition (i < N?) at the start of the loop, and it would be nice to have a way to encode (i<N and MY_TEST) into the pre-test portion. That would solve two problems:
1) I don't like using the While Loop because of the constant need for an embedded case structure around the entire contents of the loop to decide whether to execute or not.
2) I have to have case structure around the entire loop to decide to skip the loop entirely. If I could just "and" onto the For Loop's existing test, then the loop could execute zero times without adding another structure.

Putting the stop terminal inside the loop doesn't help any of that. So I'm sort of a reluctant supporter of the For loop's stop terminal. It helps, but because of its location it misses uses cases, so I wonder if there might be a better idea from anyone?
Member
Joris Robijn
Posts: 8
0 Kudos

Re: For Loop with Break

Jaegen, the code size difference shows exactly why it would be such a good feature! (Although it could have been done without the case structure and cutting at the end, but that is a difficult construction which is prone to error).
 
Stephen, the "real" While loop sounds interesting. I would think of a flat-sequence-like structure in a loop, because you need to enforce the decision is made before the (other) looped code. I hope there's a way to make something like that without becoming too big. I don't like sequence structures at all.
 
Joris
 
Active Participant
Kevin_Price
Posts: 1,906
0 Kudos

Re: For Loop with Break



I like it, but is there any way you can come up with to make this a decent pre-test loop instead of a post-test loop? The For Loop tests its loop condition (i < N?) at the start of the loop, and it would be nice to have a way to encode (i<N and MY_TEST) into the pre-test portion...

Putting the stop terminal inside the loop doesn't help any of that. So I'm sort of a reluctant supporter of the For loop's stop terminal. It helps, but because of its location it misses uses cases, so I wonder if there might be a better idea from anyone?


An ugly thought for early Break:  have a right-click option on the stop terminal to designate whether or not outputs should be updated on the iteration where an early Break occurs.  The default behavior would be a post-loop test (like today's While loop that also uses the Stop terminal), but the equivalent of a pre-loop test can be selected.  Some visual clue would need to indicate the mode -- perhaps the Loop boundary since the mode affects ALL outputs.

As to the iterator options, I would suggest a right-click option on the Loop boundary for "show iterator terminals".  The terminals would be i_init and i_inc, both represented as i32 values.  If unshown or unwired, the defaults would be i_init = 0 and i_inc = +1. 

I would purposely NOT include an i_final terminal.  Having one can lead to conflicts with auto-indexing or a wired "N", which would require precedence rules.  It would also lead to confusion for cases where someone has i_init=0, i_inc=5, and i_final = 12.  Should it terminate at i=10 or at i=15?  I believe that any desire to use an i_final termination condition can be readily accomodated by wiring through and using the "Break" terminal with the mode option described earlier.  This is also likely to make the termination logic more explicit.

-Kevin P.

-- looking to hire? PM me...
Knight of NI
altenbach
Posts: 22,891
0 Kudos

Re: For Loop with Break

[ Edited ]


Jaegen wrote:

Rather than having to do something like this:



Jaegen,

Maybe I don't quite understand your code, but I think you're a bit unfair here, because your code is more complicated than needed. From what I can see, the entire case structure can be omitted without any change in outcome. Why would you need to replace an element with itself in the array if it is > 10??? That's equal to a NOOP.


Jaegen wrote:

We can do this:



We can already do this. Just use a while loop! :smileyhappy: (See image top)

One alternative, way to code the problem with the current tools is shown below. "Look ma, no loops!"

Message Edited by altenbach on 08-31-2006 08:25 AM


LabVIEW Champion . Oh, by the way, I work for peanutsKudos .

By using this web site, you accept the Terms of Use for this web site. Please read these Terms of Use carefully before using any part of this site. Please go here for information on ni.com's copyright infringement policy.
My Profile | Privacy | Legal | Contact NI © 2011 National Instruments Corporation. All rights reserved.    |    E-Mail this Page E-Mail this Page