LabVIEW Idea Exchange

cancel
Showing results for 
Search instead for 
Did you mean: 
tbob

Extra For Loop Functionality

Status: Duplicate
See links to other idea conversations below.

The For Loop is one of the most widely used tools in Labview.  However, it has a drawback.  The step size and starting point is fixed and cannot be changed.  Most of the times this is OK.  But there comes a time when being able to change the starting index and/or the step size would become very useful.  Consider the following scenario:

 

You have a test results file as such:

Test1   UUT1   3.4

Test2   UUT1   4.5

Test3   UUT1   5.4

Test1   UUT2   3.0

Test2   UUT2   4.1

Test3   UUT2   5.2

Lets say you wish to extract all the info for Test2 only.

 

With a conventional For Loop, you would have to create special code to form the index.  You could do it with a While Loop:

 

21880i44C0BE7C265E7F7F  21884i11AA5440B1FB2F3A

 

 

Or you could have an option to specify the start, stop, and step parameters:

 

21886i75DF07FB2B0F1B67

 

This could be made possible as a right click option.  The default would be for the For loop to appear and function as it is now.  But if you right click on the border, you would get an option to display and use the extra terminals, as shown below.  This is similar to what is being done with the Conditional terminal.

 

21888iA08C0E5DE4D1CEFA

 

With this option, the three values would be supplied.  The i terminal value would follow the parameters.  With a start value of 1 and a step size of 2 and a stop value of 10, the i for each iteration would be 1,3,5,7,9.

This would also apply to auto indexing when this option is chosen.  In the above test result example. the code could be made even simpler by enabling indexing:

 

21890i2F764D51ADB4B1DF

 

If the start were set to 1, step to 3, and stop to 5 (or the length of the array - 1), the output would be rows 1 and 4.  No extra code needed.

 

I think this idea has great merits.  It allows use for special cases, and it allows the normal For Loop to be continued as it is today, making it backward compatible.

 

- tbob

Inventor of the WORM Global
11 Comments
PhillipBrooks
Active Participant

Is there a reason you didn't post this in your previous suggestion "Real For Loop" from last week?

 

At the very least, you could have started this suggestion as "Based on 'Real For Loop'" suggestion from 8/1/2010...

 

 


Now is the right time to use %^<%Y-%m-%dT%H:%M:%S%3uZ>T
If you don't hate time zones, you're not a real programmer.

"You are what you don't automate"
Inplaceness is synonymous with insidiousness

aeastet
Trusted Enthusiast

It seems that once you post an idea it can not be upgraded as you think about more things. They should make it so that if you get some really good feedback that you should be able to edit the original idea to add the upgrades so that it appears in the more refined format. I do like this idea.

Tim
GHSP
tbob
Trusted Enthusiast

Aeastet is right, you cannot upgrade or edit an idea once it is posted.  I had to create a new one unfortunately.  It really is based on the Real For Loop suggestion with changes coming from suggestions and criticism made in the original post.

- tbob

Inventor of the WORM Global
RTSLVU
Trusted Enthusiast

I agree, even on my Timex/Sinclar 1000 I had in 1982 I could use for next loops like this.

 

For A = 10 to 35 Step 2

 

I could even use variables

 

For A = B to C Step D

 

And that was in BASIC.

 

========================
=== Engineer Ambiguously ===
========================
Intaris
Proven Zealot

I still strongly disagree with the automatic influencing of the indexing of input arrays.

 

Plus the situation is over-defined.  What happens if your start-stop-step has more entries than your array?  And what happens in the opposite case?

 

I think using a for loop for this operation is like going about things wrong.

elset191
Active Participant

 


@Intaris wrote:
Plus the situation is over-defined.  What happens if your start-stop-step has more entries than your array?  And what happens in the opposite case?

If you have too many iterations you index out of your array, and you debug and fix your code.  It happens all the time in other text based languages.  If you have too few iterations you index only part of your array.

 

--
Tim Elsey
Certified LabVIEW Architect
Todd S.
NI Employee (retired)
Status changed to: Duplicate
See links to other idea conversations below.
Todd S.
LabVIEW Community Manager
National Instruments
tbob
Trusted Enthusiast

@Intaris wrote:

 

I still strongly disagree with the automatic influencing of the indexing of input arrays.

 

Plus the situation is over-defined.  What happens if your start-stop-step has more entries than your array?  And what happens in the opposite case?

 

I think using a for loop for this operation is like going about things wrong.


In text based languages the For Loop works exactly like this.  Its up to the programmer to code properly, to not overrun the array size.  Should NI remove local variables from Labview because of the problems caused by bad programmers?  No.

 

There may be times when I want to do some operations on the first 10 elements in an array.  I can use Array Subset, then feed the sub-array into a For Loop.  Or I could just specify start, stop, and step, and let the autoindex take care of getting only the elements I want without having to use Array Subset.  I could go a step further if the default values for start and stop is 0, and the default for step is 1.  Then I just have to wire  in the stop value.  Less coding, fewer mouse drags and mouse clicks.  This would bring the For Loop up to par with other languages.

 

Don't worry, you could always use the For Loop as it is if you don't like the new feature.  But please let those of us who want the added functionality have it.

I wish I could edit the initial post.  I would like to add that the default values for start and stop be 0, and the default value for step be 1.  This way we would not have to wire in all of the values if we don't need to.

- tbob

Inventor of the WORM Global
Alex_Pi
NI Employee (retired)

I really like this idea!

I would like to give Kudos for it but its disabled due to the status. So I just give a thumbs up this way.

tbob
Trusted Enthusiast

@Alex Pi wrote:

 

I really like this idea!

I would like to give Kudos for it but its disabled due to the status. So I just give a thumbs up this way


I don't think its fair that NI disabled the Kudos button because this was considered a duplicate idea.  Now this idea may never get through.  The part that is different than the other posting is that you can right click to add the additional terminals, otherwise its the same old For Loop that we have now.  So the idea really is not an exact duplicate.

 

Alex, since your ID is in blue, I assume you work for NI.  Please bring this up to R&D's attention.

 

- tbob

Inventor of the WORM Global