LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

in what case there is no need to indicate N in for loop

i find that sometimes it must indicate N in for loop,and sometimes it doesn't ,
i want to know in what case it don't need to indicate N in for loop.
0 Kudos
Message 1 of 4
(2,985 Views)
If you wire an array to a For Loop, you can read and process every element in that array by enabling auto-indexing. When you enable auto index, N is decided by the first dimension of that array. Then, you don't need to indicate N explicitly.

帖子被ttrr在10-18-2006 04:41 AM时编辑过了

0 Kudos
Message 2 of 4
(2,983 Views)
Be careful if your autoindexing array can aver be empty. A for loop which executes zero times may have output values which are not what you wouuld expect. For most datatypes the output will be the default value. If this can happen, search the archives for a discussion of this.

Also, if you have more than one array autoindexing and the sizes of the first dimensions are different, I think the loop stops at the end of the smaller array.

Try some simple examples to learn for yourself what happens under these special cases.

Lynn
0 Kudos
Message 3 of 4
(2,957 Views)


@johnsold wrote:
Also, if you have more than one array autoindexing and the sizes of the first dimensions are different, I think the loop stops at the end of the smaller array.

More specifically, even if you wire N with a large number, a FOR loop will not loop more than the size of the smallest autoindexing array.

The loop count is determined by the smallest number of [all autoindexing array sizes, value wired to N (optional if autoindexing array inputs exist)].

One empty autoindexing array will cause skipping of the entire FOR loop.

(Sometimes it is useful to run a loop only for the first N elements of a large array. In this case you would autoindex the array, but wire a smaller number to N ;))

0 Kudos
Message 4 of 4
(2,948 Views)