LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Help with program efficiency, stopping a for loop?

Solved!
Go to solution

Hello everyone,

 

I need some general programming advice to help my VI run more efficiently.  I have a 2d array in which the program cycles through each point and compares the value to the surrounding points.  The user can select the cell range range to inspect, so if the user selects 1, then it will compare the (0,0) point to all the cells within one cell.  If the user selects 2, then all the cells within a 2 cell range, and so on.  If the (0,0) point is greater than all the points around it, then it writes that point to an array.  

 

I made more notes in the VI to explain what's going on, but I think the program would run more efficiently if I could stop a for loop from running as soon as it finds a false condition, ie the (0,0) is not greater than one of the surrounding points.  As it is right now, it compares it to all the points around it, writes TRUE/FALSE to an array, then checks to see if all the conditions are TRUE.  That takes a long time if the user selects a value of 8, for instance.  It would minimize a lot of processing time if it just kicked to the next point as soon as it found a FALSE condition.   

 

Any other advice would be appreciated as well.  Trying to be a more efficient programmer! 

 

Thanks!
Alex

 

I did not attach the data file because it is too big.

 

 

0 Kudos
Message 1 of 4
(2,645 Views)

right click at the dege of your for loop and select conditional terminal, this will work just like the terminal of a while loop, you can terminate your loops early just as you want to.  I love this because you get the best of both worlds with little change to the code.

 

It is not avaliable in earlire versions of labview (pre 8.5?)

Paul Falkenstein
Coleman Technologies Inc.
CLA, CPI, AIA-Vision
Labview 4.0- 2013, RT, Vision, FPGA
0 Kudos
Message 2 of 4
(2,610 Views)
Solution
Accepted by AlexP1

In versions before the invention of the For Loop with conditional stop terminal, you can do this, but you have to wire it up as a while loop where you stop when your condition is True, OR when the i terminal is equal to the size of the incoming array - 1.

 

 

0 Kudos
Message 3 of 4
(2,607 Views)
Thanks for the help!  I have LabVIEW 8.2, so I had to change the for loop to a while loop.  It wasn't too much additional work.  Now it runs significantly faster!


0 Kudos
Message 4 of 4
(2,565 Views)