LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Looping of elements in an array

Solved!
Go to solution

I am making a program in which i am having an array of instruments out of which some i need to program repeatedly, for which i am using  for(no. of times i need to repeat sequence of instruments) and then in the end i am using End(For) ehich will stop the execution of all the instruments in between for loop.

but i am not able to sort out how to do this so that if in whole array, anywhere either in the end or in the middle whereever i put this for and End(for) program should repeat the execution.

 

Below i am attaching the example program. 

0 Kudos
Message 1 of 16
(2,997 Views)

Use total 2 for loops. One for outside which is normally you are using and inside one is for max number of time you want to repeat for C or D(as you told in your VI). Use conditional terninal to terminate inner for loop.

 

 

--------------------------------------------------------------------------------------------------------
Kudos are always welcome if you got solution to some extent.

I need my difficulties because they are necessary to enjoy my success.
--Ranjeet
0 Kudos
Message 2 of 16
(2,991 Views)

For the Input you have in your VI please tell us what you want the output array and second subarray to contain after the VI ends.

 

I have some ideas but do not want to guess at your real intentions.

 

Lynn

0 Kudos
Message 3 of 16
(2,950 Views)

Thanks Ranjeet_Singh & Johnsold for the reply,

 

t when i am using second for loop to repeat the C & D maximum no. of times it is running fine if am not adding any instrument after end(for) array but if i am adding any instrument after End(For) then it is executing instrument after End in between the loop, there i am getting the problem.

 

Johnsold

 

in this example program i am using output array just to see wheter for loop os executing particular no. of times  or not because if it will execute 3 no. of times then the value corresponding to C& D should also come particular no. of times in the array.

 

and in second subarray i am trying to take out only those elements which are within the for loop.

 

Below i am attaching my original program which is little complicated, but you can get the idea of how output is required.

 

in this program i am able to run instruments before for loop and within for loop but if i am adding any instrument after for loop then it is executing those elements in between for loop instead of after for loop.

 

 

0 Kudos
Message 4 of 16
(2,934 Views)
Solution
Accepted by topic author RChoudhary

Why don't you simply process the inputs and unroll the loops, for example as in the attached simple modification (LabVIEW 2011).

 

(Of course you probably need to do some more syntax checking and error handling. If you want to also allow stacked loops, it would need more code)

 

Modify as needed.

 

 

Download All
Message 5 of 16
(2,924 Views)

Thanks altenbach for the reply,

 

one thing i am not getting in your code why your are usng that case structure (which will execute as per no. of elements in for loop) in default case, what if default case never comes in thre program, working of that case structure that i got but why we are using it in defualt case, 

0 Kudos
Message 6 of 16
(2,896 Views)

Ritu wrote:

one thing i am not getting in your code why your are usng that case structure (which will execute as per no. of elements in for loop) in default case, what if default case never comes in thre program, working of that case structure that i got but why we are using it in defualt case, 


Does the code work for you or not? Remember, you need to process the entire command sequence once, then use the output to sequence your code parts.

 

If it does not work, you should question my algorithms, but if it works, you should try to figure out why. 😉

 

If your sequence of commands does not contain a "for" statement, the number will always be zero and the default case will never execute. That's a good thing, because we don't need it under this scenario. If there is a "for" statement, the default case is used to collect all statements in a seperate shift register until the "end" statement is encountered, at which tiime they are all unrolled into the main sequence. Use execution highlighting and play with various inputs in order to understand how and why it works.

0 Kudos
Message 7 of 16
(2,876 Views)

I was not questioning your algorithm, i just wanted to know why we used it in default case, because i need to implement this in the original program so i wasn't able to get how to use or implement this, but now i got it thanks.

 

I have implemented it and it is working fine, but to implement nested loop, how to proceed and one more thing I am using one more type of loop for giving control values at start like Loop(1,2,3...) and then in between this some instruments and then at the end End(Loop), i have posted the query for this sometime earlier also(http://forums.ni.com/t5/LabVIEW/executing-listbox-items-according-to-loop/m-p/2479826#M758139), this is working fine if am running just Loop without any for element but again i am getting problem here if i want to run this in b/w the instrum,ents or within the for loop then it is not executing as expected.

 

please help me in sortng out this

 

 

0 Kudos
Message 8 of 16
(2,843 Views)

To support stacked loops (loops inside loops), you can implement something similar. Easiest would be something recursive. Do you really need that?


@Ritu wrote:

... if am running just Loop without any for element but again i am getting problem here if i want to run this in b/w the instrum,ents or within the for loop then it is not executing as expected.


Sorry, you are not clear here, because we don't really know what you expect. Can you describe the problem in more detail, maybe attach a VI with problematic inputs as default values?

0 Kudos
Message 9 of 16
(2,840 Views)

Thanks for the reply,

 

i will try to implement stacked loop, what does recursive means, means i need to repeat the same code or it's something different, and no stacked loop is not that priority for Aa time being but later we need to implement this so if it's not that difficult i wil do it

 

and for my Loop problem i am attaching the code which might clear the problem i am facing.

0 Kudos
Message 10 of 16
(2,837 Views)