LabVIEW Idea Exchange

cancel
Showing results for 
Search instead for 
Did you mean: 
0 Kudos
A-T-R

For Loop last iteration indicator

Status: Declined
Idea declined by submitter

Hi all,

 

it would be useful if the FOR LOOP had an indicator which is set to true on the last iteration of the loop. This terminal could also be set to true if the conditional terminal is used to abort the loop.

 

My use case:

If have various "channels" (Bits and Bytes) over which I communicate with an external ProfiBus device. These channels are identified by enums. The data values themselves are organized in a predefined numeric array in a FGV, and depending on the enum value I replace parts ("chunks" of bytes) in the array.

 

In most cases, I have to update more than one parameter in the external ProfiBus device. I change the values in the data array FGV using a for loop, and after the last array subset replacing action, that is in the last iteration of the loop, I actually transfer the new data array via an "update ProfiBus" notifier.

 

To "detect" the final iteration, I could check  "i < (ArraySize - 1)", which means to have this additional (tiny) piece of code in each iteration. Another option - which I currently use - is to provide an addtional array to the loop with just as much boolean elements as in the "channel enum array", in which only the last element is set to true, to set the "update notifier" only once.

 

To make it short:

Please provide an additional for loop indicator which is set to true in the last iteration of the loop.

 

Greetings

A-T-R

8 Comments
PNR
Member
Member

> ...after the last array subset replacing action, that is in the last iteration of the loop, I actually transfer the new data array via an "update ProfiBus" notifier....

 

The way I understand you problem, you just have to notify the transfer after the for-loop finished executing.

 

Other than that the last iteration is easy to identify as you already mentioned ( i >= N - 1 ). Thats not too complicate to implement and also does not happen very often in my opinion.

 

jcarmody
Trusted Enthusiast

Example_VI_BD.png

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

A-T-R
Member

@ jcarmody:

 

Oooops...I should have played a little with LV before posting...I work with LV for more than 10 years now, but I never - NEVER - thought that the N terminal provides the total number of iterations even without an input value.Smiley Frustrated

 

I gotta go...

 

Though my idea can be very easily implemented programmatically, I would find a integrated terminal/indicator very handy...hm...but it's a very low priority idea now...Smiley Tongue

 

Regards

A-T-R

crossrulz
Knight of NI

I still don't see how this would be useful at all.  If someting is to only happen on the last iteration, it doesn't belong inside of the loop.  It should be done AFTER the loop.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
A-T-R
Member

Hi crossrulez,

in general, you're right.

 

In my application, I encapsulated both the replacing of the several array subsets as well as the one-time firing of the "update notifier" in one FGV, because I wanted no separate code to be manually placed after the for loop every time I use my "Set Profibus values". Instead, I wanted the code closely placed together, but only partially executed, depending on a input parameter (T-F) of the VI.

 

As I write this, I'm thinking of changing my FGV code...I could put the replacement loop inside the FGV, and everytime the VI is called the loop will be executed...either only one time, or n times...and after the loop has finished, the notifier will be fired. One thing to keep in mind would be to build the VI to accept arrays of channels to be updated, or only a single channel. Hm...seems doable...

 

This has become an off-topic discussion right now...but nonetheless the idea exchange has worked for me, though not in the intended way of this forum...

 

Thanks for your input!

 

Regards

A-T-R

jcarmody
Trusted Enthusiast

@crossrulz wrote:
I still don't see how this would be useful at all.  If someting is to only happen on the last iteration, it doesn't belong inside of the loop.  It should be done AFTER the loop.

That was my first though, too, but I didn't think this would be received well. 😄

 

Example_VI_BD.png

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

Darren
Proven Zealot
Status changed to: Declined
Idea declined by submitter
A-T-R
Member

@ jcarmody:

 

 

Hm...nice example. Though I'm not sure if I should laugh or cry...