Jim Kring Posted July 8, 2008 Report Share Posted July 8, 2008 [cross-post] Hi All, I've written an article about a new feature in LabVIEW 8.5 that I think is really useful. LabVIEW 8.5 Feature - For Loop Conditional Terminal As usual, your feedback is most welcome Thanks, -Jim Quote Link to comment
Mellroth Posted July 9, 2008 Report Share Posted July 9, 2008 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 Quote Link to comment
shoneill Posted July 9, 2008 Report Share Posted July 9, 2008 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. Quote Link to comment
mje Posted July 9, 2008 Report Share Posted July 9, 2008 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. Quote Link to comment
TobyD Posted July 9, 2008 Report Share Posted July 9, 2008 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. Quote Link to comment
crelf Posted July 9, 2008 Report Share Posted July 9, 2008 QUOTE (TobyD @ Jul 8 2008, 11:13 AM) I disagree with the idea that using the new feature is a "lazy way out which complicates things unnecessarily." There’s bound to be resistance to every new feature of LabVIEW. I don’t think there’s any real reason to shun new funcitonality just because it can be done in a different way that forces you to think in a certain way. I think that most relatviely experienced programmers understand the power (and responsibility) of the conditional terminal foor loop. I agree that it could be abused by people new to programming, but that can be applied to just about everything in LabVIEW (cross-post from http://thinkinging.com/2008/07/07/labview-85-feature-for-loop-conditional-terminal/#comment-12455' rel='nofollow' target="_blank">here). Quote Link to comment
Omar Mussa Posted July 9, 2008 Report Share Posted July 9, 2008 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). Quote Link to comment
Mellroth Posted July 9, 2008 Report Share Posted July 9, 2008 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 Quote Link to comment
Aitor Solar Posted July 11, 2008 Report Share Posted July 11, 2008 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 Quote Link to comment
Phillip Brooks Posted July 11, 2008 Report Share Posted July 11, 2008 QUOTE (Aitor Solar @ Jul 10 2008, 07:47 AM) 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. This issue was discussed in the Feature Brainstorming forum on NI (see here), but it doesn't discuss what method the final implementation uses. Good reading in any case. Quote Link to comment
TobyD Posted July 11, 2008 Report Share Posted July 11, 2008 QUOTE (Aitor Solar @ Jul 10 2008, 04:47 AM) 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. 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. Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.