LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

For Loop Exit

Solved!
Go to solution

Hi there, i am writing a program that requires a break in the for loop. However, I am using Labview 7.1, and it doesnt have a conditional exit. If anyone can give me some suggestions, I would appreciated it. 

 

Derek

0 Kudos
Message 1 of 14
(4,432 Views)

You can turn on indexing for a while loop. This should give you what you need.

 

Example_VI_BD.png

Tim
GHSP
0 Kudos
Message 2 of 14
(4,429 Views)

Thanks a lot! But could you tell me how you got the yellow window and conditional exit on that while loop. I am not a proficient user.

0 Kudos
Message 3 of 14
(4,425 Views)

If you connect the array to the while loop you can right click the tunnel and one of the options is enable indexing. The while loop automatically comes with the stop feature. It is located on the tool pallet.

Tim
GHSP
0 Kudos
Message 4 of 14
(4,418 Views)

I use the for loop so that I can control how many iterations it runs. How will this work? Does the number of elements i make in an array determine how many iterations this loop will run?

0 Kudos
Message 5 of 14
(4,402 Views)

No, you need to compare the iteration count [i] with the desired number of iteration and stop accordingly. Use a boolean OR of this condition with the stop button to stop under both conditions. 

0 Kudos
Message 6 of 14
(4,396 Views)
Solution
Accepted by topic author j49sun

In this example if you look.

 

Example_BD.png

 

The top part looks to see how big the array is and stops if the iterations are larger than the array size. The bottom one stops the code if the user pushes the button. You can add as many things as you want to stop this loop.

Tim
GHSP
0 Kudos
Message 7 of 14
(4,387 Views)

WOW THANKS thats brilliant!!!  So basically you can stop this loop when the iterations have been completed or when you click a button.  Is the true frame the samething except it's a true output to the Or Boolean? 

0 Kudos
Message 8 of 14
(4,373 Views)

Yes I added the case structure so yo ucould see that you can place more code in the case structure and do something there too. I hope this gets you started.

Tim
GHSP
0 Kudos
Message 9 of 14
(4,369 Views)

You do not have to include the upper test in your loop. If you use the auto-indexing you get that for free. The while loop will run as many iterations as there are array elements (provided whatever other conditions you test to stop the loop are not met).

 

The one thing to be aware of though is if you connect more that one array the number of iterations run will be equal to the size of the smallest array. If you have an empty array the loop will not run.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 10 of 14
(4,361 Views)