LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Sequential operation of logic and loops

Hi,

I have some code set up to match two list together. To do this I have a while loop which loops through one list and then a for loop inside that loops through the other list (not very optimized I know, but forget that for a second). I want to find the best match, so I keep track of how close things come during each iteration of the for loop and save the best result. The problem is that the for loop executes once and then it moves on to the rest of the code that I had which checks whether a match was made. It C this wouldn't be a problem because things would excute in sequence, the for loop then the rest of the code. But here LabView seems to want to do things in parallel or I don't know what. I tried sticking a sequence structure around things so that the for loop and it's logic would complete before moving on, but as soon as my variables become valid, which they are after the first time through the for loop LabView moves on and I get the same problem. I've been using the debugging stuff, and I'm pretty sure this is the problem, ie. the loop is not looping, it does the first iteration and then moves on. What am I doing wrong and how do I fix it? I've included code.

Thanks for any help,
Chris
0 Kudos
Message 1 of 6
(2,922 Views)
You're right about your loop only running once, but that's because you've wired a single element 1-d array to it as an indexing input.  I'm not entirely sure what you're trying to accomplish with that, so I can't offer any suggestions, other than that's why it's only running once.

Message Edited by Novatron on 07-11-2005 02:48 PM

0 Kudos
Message 2 of 6
(2,916 Views)
The problem is that you're wiring an array of size 1 to the top of the for loop. The number of times a for loops iterates is the smallest number - either of what is wired into its N terminal or of the smallest array auto-indexed into it.

___________________
Try to take over the world!
0 Kudos
Message 3 of 6
(2,913 Views)
I think your problem is a misunderstanding of for loops and how many times they with iterate. You have two methods to control the iteration count. You can wire a value to the "N" terminal or you can input an array with auto-indexing turned on. You've got both in your program. In the upper left of your diagram, you have a delete from array function and the deleted portion of one element is wired into the for loop and auto-indexed. When you have both the "N" and a array (or multiple arrays) it will use the smallest number for the iteration count. Since you have an array with only one element, that is why the for loop only runs once.
0 Kudos
Message 4 of 6
(2,904 Views)
Thanks Dennis,

I had no idea that a for loop acted differently depending on the variables flowing into it (with the arrays). I was just picturing it as a normal for loop (from C or something), N was getting the correct value to iterate too, so I couldn't figure out for the life of me why it wasn't looping more then once.

Thanks a lot,
Chris
0 Kudos
Message 5 of 6
(2,889 Views)
Do you know that you can turn autoindexing off?  Right click on the array input terminal on the For Loop's border.  Select Disable Autoindexing.  If all array inputs have autoindexing disabled, the N terminal will be used as the sole condition for how many times to loop.
- tbob

Inventor of the WORM Global
0 Kudos
Message 6 of 6
(2,884 Views)