12-02-2020 01:54 AM
Hello everyone,
I am working on a project where I have for-loop inside a while-loop which iterates continuously until I stop the while loop.
I want to create an array of elements in the below fashion,
for the first 300 iterations (0-299), I need the array elements to be 1 and 2 for next 300 iterations (i.e. 300-599).
Likewise, I want to create an array of elements from 1 to 20.
can anyone help me with this?
Thanks and regards,
VigViv
12-02-2020 02:04 AM
Hi VigViv,
@VigViv wrote:
I want to create an array of elements in the below fashion,
for the first 300 iterations (0-299), I need the array elements to be 1 and 2 for next 300 iterations (i.e. 300-599).
Likewise, I want to create an array of elements from 1 to 20.
Do those iteration counts refer to the While loop? Or to the (inner) FOR loop?
Why do you need a FOR loop, when you could use InitArray to create an array?
What have you tried so far? Where are you stuck?
12-02-2020 02:16 AM
Hi GerdW,
No, the iteration count refers the for loop.
I figured it out. Anyways, thanks for your quick reply. 🙂
I am attaching the screenshot of the logic I used for future reference.
Thanks and best regards,
VigViv
12-02-2020 03:32 AM
Hi VigViv,
suggestions:
12-02-2020 10:12 AM - edited 12-02-2020 10:25 AM
@VigViv wrote:
No, the iteration count refers the for loop.
I figured it out. Anyways, thanks for your quick reply. 🙂
I am attaching the screenshot of the logic I used for future reference.
![]()
This code makes absolutely no sense because you are constantly re-doing work you already did in previous iterations of the while loop. All you need to do is retain the current array in a shift register and append one (!!) new element per itations of the while loop. The FOR loop is not needed. Ultimately you'll run out of memory, of course.
Also, next time please attach your VI. Pictures are useless for debugging.
I think the following would do about the same, but there are plenty of other ways to do this.
12-02-2020 10:53 AM
@VigViv wrote:
I want to create an array of elements in the below fashion,
for the first 300 iterations (0-299), I need the array elements to be 1 and 2 for next 300 iterations (i.e. 300-599).
Likewise, I want to create an array of elements from 1 to 20.
See if this gives you some ideas. If you want all the intermediary shorter arrays, place the indicator and wait inside the loop.
12-02-2020 10:59 AM
If you are only interested in the final array, this would also work. (Note the concatenating output tunnel)
12-03-2020 05:02 AM
Hi Altenbach,
Thanks for your message. I can definitely use one of your solution.
Best regards,
VigViv
12-03-2020 05:05 AM
Hi GerdW,
Thanks for your suggestions. I will definitely consider those.
Best regards,
Vignesh