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
Trusted Enthusiast
Albert.Geven
Posts: 3,151
0 Kudos

Re: For Loop with Break

Hi Robbie

Splendid idea

But.... the problem we have is to end a while loop as easy as the for loop when arrays are involved.
first asking the size of the array, then subtracting one and in the for loop a compare with the index !
You could also add a primitive to an indexed tunnel that signs the last real element.
Only an empty array still needs a solution
 
The small extension is the letter e for empty.
 
The idea of the timed loop approach is nice for the increment and start value of the index but too complex for simple users.
This more in style with shift registers extended to more than one history level, maybe also the solution when special thing should happen for empty arrays. But a case inside for the empty array is also possible of course.
greetings from the Netherlands
Member
natemoehring
Posts: 13
0 Kudos

Re: For Loop with Break

I agree with everything Robbie said, I have long wished for these features, especially the "break" feature.  I think the condition terminal can keep it's original name, the user just has to understand the condition is actually compound: the condition boolean input and the N/auto-indexing.  I think it should be an enable-able option by right clicking on the border of the for loop.

Speaking of "break", I have also long wished for a "return" or "End <owner>" capability similiar to other textual languages.  However, I understand the dataflow programming for the output using these hypothetical primitive nodes could be complex, requiring the user to use additional local variables to make sure variables are retained correctly.  Just a thought.

Active Participant
Henrik_Volkers
Posts: 1,806
0 Kudos

Re: For Loop with Break

I like the Flex loop idea too. Merge the While and the For loop, add some pepper (start value, increment, type, stop.. great list altenbach) and salt (you need to know what you want, a lot of options.. for bugs:smileywink:)

Oh, and I want both kinds of index (country and western) a free type one with x_0, dx and optional x_stop AND an index for my arrays at the same time.

And an optional boolean for first interation (no need to check if i=0 ) 

Greetings from Germany
Henrik

LV since v3.1

“ground” is a convenient fantasy

'˙˙˙˙uıɐƃɐ lɐıp puɐ °06 ǝuoɥd ɹnoʎ uɹnʇ ǝsɐǝld 'ʎɹɐuıƃɐɯı sı pǝlɐıp ǝʌɐɥ noʎ ɹǝqɯnu ǝɥʇ'
Member
Imaginatics
Posts: 22

Re: For Loop with Break

[ Edited ]
Hi Robbie,

Great feature idea. I have wanted this for a long time and have heard several other wireheads pine for it over the years. Now as to the specifics (remembering Mr. Mercer's post of IFLV a couple days ago about how to make a request of NI R&D).

I won't go through all the steps here because you have already supplied the first few. As to implementation, I wish we had a new termination icon, different from the while loop (or actually make the while loops like this as well.

What I'd like is an arbitrary type wire terminal with an optional compare value along with the current match on true or match on false options. We already have a minor inkling of this in the while loop in that we can wire in an error cluster and we can stop on error or continue while error.  If you are going to bother to make the change lets make it really useful, otherwise we already have the while loop workaround.

I've attached a jpg of what I am thinking of . I use an error cluster, but only as an example,  We should be able to wire any arbitrary type into the upper loop and then the exact data match value for that type in the lower terminal.  In the example it is an error cluster, but it will not halt on any error, only specifically on error 56 (can you tell I've had issues with TCP timeouts in the past?)

Message Edited by Imaginatics on 02-17-2006 10:40 AM

Message Edited by Imaginatics on 02-17-2006 10:44 AM

Message Edited by Imaginatics on 02-17-2006 10:45 AM

Active Participant
Jim_Kring
Posts: 1,731
0 Kudos

Re: For Loop with Break

Yes, gimme a (For Loop) break.
Thinking in G
Member
dambored
Posts: 21

Re: For Loop with Break

Hi all,

The first question in my mind is why?  I know that there have been a large number of people asking how to break out of a for loop.  I have had to break out of a for loop before.  Some people don't realize you can auto index with a while loop but if you use a while loop you have to check the iterations or you can make and infinite loop.  Would adding a break to a for loop slow its execution speed down if not used?  Is it necessary to replicate some of the functionality of a while loop in a for loop or should the while loop be improved to have similar capability like the for loop.  To be able to stop exectution after all the iterations are complete, perhaps an output terminal that signifies loop completed by running out of data.  I use that kind of idea in my code.  If there is an array being built during loop execution and it is stopped early does the last item get added to the auto built array and if so how does the LabVIEW programmer know this, will the last piece of data be valid?  I guess this could be an option.  This sort of thing falls into the same category as the behaviour of the default outputs of a for loop if the for loop doesn't execute.

If there was going to be a new beast my personal preference would be for a hybrid loop and leave the current for loop and while loop alone.  There is quite a bit of difficulty converting my 3000 VI project from LV7.1 to 8, how can you ensure the upgrade from the current loops to this kind of loop will be painless?  That leads to all kind of other questions...So I won't go there.  I really like the idea and I can see myself using it but are we adding functionality for the text based converts at the cost of execution speed and increased complexity of the now beautifully simple for loop.  Any sort of options that you have to use the menu to configure take time.  Any more code or checks you add to the loop will slow it down.

To answer your questions

1.  A new loop with the stop terminal showing, if you can run the conditional terminal unwired can you get that capability back into the standard while loop.  I really miss that.
2.  Same icon, less to confuse new programmers, allow error input and to stop if true or stop if false.
3.  Conditional terminal just like a while loop, less terminology to learn.
4.  Yes

Thanks for reading,

Dean Mills




Member
Joris Robijn
Posts: 8
0 Kudos

Re: For Loop with Break

Hi,

 

A break in a for would be nice. Right now, you need to do a lot of work to convert a for loop into a while loop. An option in the for loop to have a stop symbol would be great.

 

I think it's good to watch these points:

1. Keep it ELEMENTRY. Don't combine this feature with other features like error comparison, there are other ways to do that much better and in your own way (everyone wants that in a different way). Just boolean.

2. Keep it FAST. The preallocated auto indexing stuff is a major advantage of a for loop.

3. Keep it INTUITIVE. Right now, you know how many items go out. This should also be the case with the stop in place. So the preallocated array should be cut of when the loop is broken.

 

The difference between a while and a for will remain: a for loop has a predefined maximum #loops, which determines the size for preallocation of tunnel arrays. A while loop has no set maximum.

Passive indexing tunnels ? Hmm sounds nice ! Should be very well distinguisable though !

The zero elements input array is no problem at all. The while loop will not run, as the maximum #loops is 0.

 

Joris

CIT Engineering

 

Trusted Enthusiast
Albert.Geven
Posts: 3,151

Re: For Loop with Break

Hi Joris

At the moment a while always executes at least once !

greetings from the Netherlands
Active Participant
EdDickens
Posts: 1,656
0 Kudos

Re: For Loop with Break

I like all the ideas here and most, if not all are something I've wished was possible at one time or another.

The thing I can't tell is if you are talking about adding all this functionality to the For loop, or making a new structure (think Timed Loop) for all the new stuff and leave the current For loop as it is.

I'm in favor of keeping the current For loop and adding a new one. I think the one big benefit of doing it his way would be to avoid upgrade issues. Plus it would also be nice to have the current one available so you won't have to bother with the configuration when you know you just need a standard For loop.

Ed


Ed Dickens - Certified LabVIEW Architect - DISTek Integration, Inc. - NI Certified Alliance Partner
Using the Abort button to stop your VI is like using a tree to stop your car. It works, but there may be consequences.
Member
Joris Robijn
Posts: 8
0 Kudos

Re: For Loop with Break

Hi Albert,

> At the moment a while always executes at least once !

Ah yes, I meant a for loop of course !

Joris

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