LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

It is possible to insert a while loop inside a for loop?

Hi,

 

I would like to insert a while loop inside a for loop. In particular I would like to identify N subarray from an INPUT using a for loop. Then, for each subarry, I would to identify a particular vale of the subarry using a while loop. Then, once that this vause has been identified, the for loop should run with the second iteration. It would be possible to do something like the example attached? Many thanks, Davideesempio.png

0 Kudos
Message 1 of 18
(5,550 Views)

first, yes you can put loops in loops (e.g. while- inside of for-loops or vice-versa)

 

i cleaned up your "example" a little

 

it is not clear what you really want to do,

please be a little more pseudocodish,

or explicit in what inputs and what is the output you want.

 

 find-compare-subarrayelements.png

 

<edit>

NOTE that with the small values (0 to 1) from random .. the while loop never leaves the first iteration

 

and no meaningful output exists, except that maybe the while- or for-loop stops (for sensible values in input array)

</edit>


If Tetris has taught me anything, it's errors pile up and accomplishments disappear.
0 Kudos
Message 2 of 18
(5,532 Views)

Hi jwscs,

 

many thanks for your replay.

 

My input is1 column file (.txt). This represents a pressure time hystory of about 100 seconds. Due to the fact that I have an individual event each 10 seconds, I would like to identify before these 10 subarray (i.e. 10 events). Then, for each of them, I would like to identify a particular value inside each event. When this is identified by the while loop, I would like to stop the while lope and to save this stop value in a file (.txt) using write file. Therefor I would obtain a final .txt file with these 10 values (while the input could be given by 1000 data). Consequently, when the first output value (realted to the first subarry) is identified, the while loop should stop and it should start again the second while loop (related to the second subarray) in order to identify and to save the second value of the output. And go on....I don't know if I was clear. Thanks, davide

0 Kudos
Message 3 of 18
(5,511 Views)

Please below the sketch.esempio.png

0 Kudos
Message 4 of 18
(5,494 Views)

please split you text more (pseudocodish)

 

what is the criteria for the "particular value"?

 

for saving the "particular value" you can make a conditional indexed output

 

i made a better example

 

find-compare-subarrayelements-2.png

now it even ends 😉

 

<edit>

the conditional auto-indexing is superfluous,

sine the loop stops when something is "found", Tunnel-Mode should be "last-value",

and then the "conctenating" a "auto-indexing"


If Tetris has taught me anything, it's errors pile up and accomplishments disappear.
0 Kudos
Message 5 of 18
(5,482 Views)

Rube Goldberg Alert!

 

Please tell me that someone else put that bit of code in your while loop and not you.

 

 

(I needed to post this exact same reply on someone else's message last week.)

0 Kudos
Message 6 of 18
(5,461 Views)

mhh .. as you might have seen .. i got other things on my mind 😉

it is also superfluous,

was reimplementing without thinking

 

interesting thread all the same .. thx


If Tetris has taught me anything, it's errors pile up and accomplishments disappear.
0 Kudos
Message 7 of 18
(5,446 Views)

Hi,

 

the criteria about the particular value is: if (i+1)>10(i), then it is ture (i.ie if the value of i+1 is, at least, 10 times i).

 

In other words, I have an INPUT of 1000 data points. I want to identify 10 windows of 100 data points each. For each window I want to identify just 1 value (with criteria above) and to save this true value. Then my output should be a .txt file with 10 values (one for each window identified using the for loop). Many thanks, davideesempio.png

0 Kudos
Message 8 of 18
(5,432 Views)

i think that should do it

replace/add your data source and output

 

BTW you can drag and drop the snippet onto a Block-Diagram window

find-compare-subarrayelements-3.png

 

sorry RESULT holds the value whos predecessor is at least 10 times smaller


If Tetris has taught me anything, it's errors pile up and accomplishments disappear.
0 Kudos
Message 9 of 18
(5,414 Views)

Many thanks!! It is working!! wowowowowow 🙂

0 Kudos
Message 10 of 18
(5,400 Views)