LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

i have a for loop inside of while loop.when i press stop for while loop, i also would like to stop for loop.how can i solve this problem?thanks

i have a for loop inside of while loop.when i press stop for while loop, i also would like to stop for loop.how can i solve this problem?thanks
0 Kudos
Message 1 of 7
(3,212 Views)
There is no way to stop a for loop. But there are at least two solutions :

1) Replace the inner for loop by a while loop.
2) Add a True/False case in the for loop.
0 Kudos
Message 2 of 7
(3,212 Views)
the demand of my application is that i can not replace for loop with a while loop.because i need fixed number of iterations and as far as i know fixed iterations could be only with possible with the for loop.
your recommended second option that i could add true/false case.
this true/false case must be inside the for loop or outside the for loop?if this case is inside the for
loop, how can i send stop command from outer while
loop?
more over do you have any example for this please?
thanks
0 Kudos
Message 3 of 7
(3,212 Views)
Hi fais,

Following through with what JB suggested. The steps involved in replacing the inner for loop with a while loop are outlined below.

You can replace the inner for loop with a while by doing the following.

1) Right-click of the for loop and select "Repalce" then navigate to the "while loop".

2) Make sure the tunnels you where indexing on with the for loop are still indexing.

3) Drop an "array size" node on your diagram. Wire the array that determines the number of iterations your for loop executes into this "array size".

4) Wire the output of the array size into the new while loop.

5) Set the condition terminal to "stop if true".

6)Drop an "OR" gate inside the while loop and wire its output to the while loops condition terminal.

7) C
reate a local of the boolean "stop" button, and wire it into one of the inputs of your OR gate. This will allow you to stop the inner loop.

😎 Drop a "less than" node inside the inner while loop.

9) Wire your iteration count into the bottom input of the "less than".

10) Wire the count (see step 4 above) into the top input of the less than. This will stop the inner loop when ever the inner loop has processed the last element of your array.

Provided I have not mixed up my tops and bottoms this should accomplish the replacement.

I will let others explain how to takle this task using the "case solution".

Ben
Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 4 of 7
(3,212 Views)
1) You can easily set a fixed number of iteration of a while loop. See Example 1.

2) Example 2 is an example with an inner for loop and a TF case. In opposite to the while loop, the for loop is not stopped but executes the empty case. If the number of iterations is big, this will take some time...

In conclusion : If there is a need to stop a loop, the while loop will be the better choice.

Hope this helps.
Download All
0 Kudos
Message 5 of 7
(3,212 Views)
I have tried doing something similar. However, I realized that the efficiency of the loops decreased by a lot. Is that normal?
0 Kudos
Message 6 of 7
(3,212 Views)
Reading from Front panel objects takes some time.

In the above we are checking the boolean repeatedly. Each check takes time so...

Yes, that is normal.

Ben
Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 7 of 7
(3,212 Views)