LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

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

This is very dangerous code, because there is a finite possibility that the inner while loop will never stop, locking up the program forever.

It also seems overly complicated.

0 Kudos
Message 11 of 18
(1,737 Views)

Are you right. This is ture, sometimes, when the signal is quite complex, the code does not stop. Please, do you have any suggestions? In wich way I could improve this cose? Many thanks, binfi

0 Kudos
Message 12 of 18
(1,730 Views)

@binfi wrote:

Are you right. This is ture, sometimes, when the signal is quite complex, the code does not stop. Please, do you have any suggestions? In wich way I could improve this cose? Many thanks, binfi


I think all you need is a single FOR loo. Here's what I would do. (Of course you need to decide what to return if the condition is never met, for example, so modify as needed).

 

 

(Left to right: reshape array, FOR loop, multiply, array subset, greater, search array, index array)

0 Kudos
Message 13 of 18
(1,725 Views)

@altenbach thx for mentioning it, if for any subarray the i and (i+1) differs less than 10*i, the while will not exit

or did you mean something else?


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

@jwscs wrote:

@altenbach thx for mentioning it, if for any subarray the i and (i+1) differs less than 10*i, the while will not exit

or did you mean something else?


Yes, just run your code a couple of times. on occasion it will continue forever!

 

(Yes, if the condition is never met and we run out of elements while processing a row, index array will return two zeroes forever, never meeting the > condition. If you would change the condition to "greater or equal" it will return zero like my code when it runs out of elements and no match has been found because we get a 0=0-->TRUE.)

 

Still, my code is probably simpler. 😄

0 Kudos
Message 15 of 18
(1,686 Views)

thats what i get, for acting without thinking, and posting pictures 😉

 

thx for the new icons i have never used. all in all i got some more knowledge out of it

 

:cheers:


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

It might be cheapest (especially with huge arrays) to avoid "reshape" and "array subset" and just operate on the unmodified array. For the inner loop, use a conditional FOR loop.

 

This code gives about the same result and does all operations on scalars, limiting memory use.

 

 

0 Kudos
Message 17 of 18
(1,663 Views)

Many thanks to both!! now it is working in perfect way!! you are genius...it was a pleasure for me having your suggestions!! Thanks

0 Kudos
Message 18 of 18
(1,616 Views)