Jump to content

Article - LabVIEW 8.5 Feature - For Loop Conditional Terminal


Recommended Posts

I really like the conditional terminal of FOR loops, but I have seen a number of implementations where the programmer uses auto indexing outputs just as on an ordinary FOR loop.

Causing all kind of strange errors in the program, errors that can be quite hard to find.

Using conditional terminal;

Length of the indexing input is not necessary equal to the Length of the indexing output, unless all iterations are completed.

Not using conditional terminal;

Length of the indexing input is equal to the Length of the indexing output.

/J

Link to comment

QUOTE (JFM @ Jul 8 2008, 10:41 AM)

I really like the conditional terminal of FOR loops, but I have seen a number of implementations where the programmer uses auto indexing outputs just as on an ordinary FOR loop.

Causing all kind of strange errors in the program, errors that can be quite hard to find.

Using conditional terminal;

Length of the indexing input is not necessary equal to the Length of the indexing output, unless all iterations are completed.

Not using conditional terminal;

Length of the indexing input is equal to the Length of the indexing output.

/J

I personally find this new feature a lazy way out which complicates things unnecessarily. I would have actually preferred an Iteration link to the stop condition of a while loop than a stop terminal in a for loop. Seems to make more sense to me as a while loop has already a non-determinate number of iterations whereas a for loop is fixed.

An option on a while loop (Stop if Auto-index limit reached) would have been a better choice to implement what is basically the same idea. It's just a different visualisation.

Shane.

Link to comment

I've always disliked how LabVIEW never had an equivalent to the break command in a for loop (or a continue for that matter), and when I heard they added the conditional for loop in 8.5 I was impressed. Your article pretty much summed up how it was done before, with the good old shift register and case structure combination, and gave a good example of how the same thing can be done now.

Granted, the use of such a conditional for loop may run contrary to many design paradigms in LabVIEW, especially for the auto-indexed nodes as already mentioned, but I always found the alternative work-arounds to be messy and franky, I'm surprised NI took so long to implement such a construct that is so common in most (if not all?) text languages.

Link to comment

QUOTE (shoneill @ Jul 8 2008, 03:44 AM)

I personally find this new feature a lazy way out which complicates things unnecessarily. I would have actually preferred an Iteration link to the stop condition of a while loop than a stop terminal in a for loop. Seems to make more sense to me as a while loop has already a non-determinate number of iterations whereas a for loop is fixed.

An option on a while loop (Stop if Auto-index limit reached) would have been a better choice to implement what is basically the same idea. It's just a different visualisation.

Shane.

I disagree with the idea that using the new feature is a "lazy way out which complicates things unnecessarily." I think Jim's article points out two use cases where the code is simplified, easier to read and more efficient.

I personally find this new feature quite useful and I implement it often. I have found that it simplifies the code in cases where I need clean "last known state" error data when an error has occurred.

Link to comment

QUOTE (JFM @ Jul 8 2008, 01:41 AM)

Using conditional terminal;

Length of the indexing input is not necessary equal to the Length of the indexing output, unless all iterations are completed.

This is actually a really useful feature of enabling the conditional terminal in certain cases (for example, autoindexing an array of strings UNTIL an empty string is found, etc).

Link to comment

QUOTE (Omar Mussa @ Jul 8 2008, 06:58 PM)

This is actually a really useful feature of enabling the conditional terminal in certain cases (for example, autoindexing an array of strings UNTIL an empty string is found, etc).

I agree, this feature is really handy.

I was just trying to point out that I have seen strange bugs, because people don't use the output iteration correctly,

and thought this was a good place to stress this difference from an ordinary FOR loop.

/J

Link to comment

In the wake of JFM words, I wonder if the conditional break affects the for loop performance. NI, in several documents (for example VI Memory Usage) says:

"If you want to add a value to the array with every iteration of the loop, you can see the best performance by using auto-indexing on the edge of a loop. With For Loops, the VI can predetermine the size of the array (based on the value wired to N), and resize the buffer only once."

Now, does adding the conditional break forces LV to resize the buffer, with the added memory allocation? That could be something to keep in mind when using this feature.

Saludos,

Aitor

Link to comment

QUOTE (Aitor Solar @ Jul 10 2008, 04:47 AM)

There was also some discussion about this in an Eyes on VIs article found http://eyesonvis.blogspot.com/2007/08/for-loop-with-conditional-terminal.html' rel='nofollow' target="_blank">here. In the discussion, Robbie says

QUOTE

With a while loop, we don't know how big an array that auto-index terminal is going to create. So, we allocate memory over and over again (in chunks, but still possibly many times) until the while loop stops. With the For Loop, we at least know the maximum size that array will be, so we only have to do one large data allocation, and then resize downward if we terminated the loop early.

To summarize, the For Loop w/Conditional Terminal is still going to be the most efficient loop.

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.