LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

What is the "best way" to draw a block diagram with a for loop?

Hello,
 
   I am using a for loop to go thru an array. What is the best way to "tell the for loop" the number of times to go thru the loop? Should I have the array be an tunnel input on the left side with indexing enabled? Or should I use the index array and the array size blocks that are connected to the "N" input in the upper left hand corner? (the array tunnel input would have indexing disabled)
 
Thanks in advance for any relies that I receive!
Smiley Happy
Regards,


Kaspar
0 Kudos
Message 1 of 5
(3,608 Views)
Easiest is an autoindexing input tunnel. This way the loop will automatically determine how many times it must repeat and you don't need to wire N.
 
(Of course it all depends on your exact needs, but if you just need to repeat a certain operation for each array element, go with the above. Most LabVIEW operations are polymorphic, so you might even be able to remove the FOR loop and things continue to work. ;))
0 Kudos
Message 2 of 5
(3,604 Views)


@altenbach wrote:
...Most LabVIEW operations are polymorphic, so you might even be able to remove the FOR loop and things continue to work. ;))

Here's one example. As you remove the FOR loop, nothing breaks and the result is still the same. 😉


Message Edited by altenbach on 07-11-2006 01:49 PM

Message 3 of 5
(3,603 Views)
Altenbach, I agree your example shows an elegant use of polymorphism. But, if the loop-less code was included in an area of a diagram with more objects, it may not be obvious "at first glance" that arrays are involved. If a programmer wanted to leave the loop in so that it was obvious that array operations were being performed, is there any other performance penalty, or would the program compile and execute identically with or without the loop? Any other drawbacks or benefits either you (or any other readers) can think of? Thanks in advance for your consideration - Brian
0 Kudos
Message 4 of 5
(3,588 Views)


@BEHajder wrote:
If a programmer wanted to leave the loop in so that it was obvious that array operations were being performed, is there any other performance penalty, or would the program compile and execute identically with or without the loop?
Some casual testing shows that a no-loop version seems to have a slight speed advantage, but never assume anything. If you are worried about performance, code both and compare the speed to be sure.
 
From the thick wires it is always obvious that "array operations are being performed", so placing an unneeded FOR loop is probably not a useful way to emphasize that fact. 😉 You can always annotate your diagram with some text boxes to explain things to the guy who wants to re-use your VI 10 years from now. 🙂
 

Message 5 of 5
(3,548 Views)