LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

For loop

Why is the N terminal in a for loop, an I32? It could be just be an unsigned integer..right? What is the exact usage of this feature?
Message 1 of 10
(3,178 Views)
Well, the array size is also a I32, so you cannot have arrays larger than the highest I32 number. It would make little sense to have N any larger.
 
The usage of N is pretty easy. It determines the number of iteration the loop will run (or at least an upper limit).
 
Of course the actual number of iteration can be less, for example if an autoindexing input array is smaller in size or if the conditional terminal receives a stop signal.
 
If you need a loop with unlimited iterations, use a while loop. 😄


Message Edited by altenbach on 06-12-2008 10:14 PM
0 Kudos
Message 2 of 10
(3,175 Views)
I agree it makes sense that N's size need not be any larger than I32. But why is that really an I32/ Array sizes & indexes are I32's? What is the necessity for it to be an I32? If you wire a negative integer to the N terminal of the for loop, it doesn't run at all.
 
Thanks,
Murali
Message 3 of 10
(3,165 Views)


MuraliK wrote:
 If you wire a negative integer to the N terminal of the for loop, it doesn't run at all.

That's a good thing, right? 🙂
0 Kudos
Message 4 of 10
(3,157 Views)
Smiley HappyIt is good. But why should it exist this way when we are not going to use it anyway?
Message 5 of 10
(3,154 Views)
The fact that the index of the for-loop is similar to the index and size of arrays is the main reason (I can think of). If you search an array for an invalid element you will get -1 (not found).
If this would be converted to an U32 for the for loop the value would be huge (2^32-1) and the for loop would spin almost forever:


Ton


Message Edited by TonP on 06-13-2008 08:12 AM
Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
Nederlandse LabVIEW user groep www.lvug.nl
My LabVIEW Ideas

LabVIEW, programming like it should be!
Message 6 of 10
(3,151 Views)
That seems to be valid point Ton. But if the Search Array function is the only Array function that uses I32 to give out -1, will not 2 outputs: index of the searched element (could be an U32 and return 0 if the element is not found) and a boolean to specify whether the element was found in the array or not, make sense?. I agree that it might be confusing to return "0" if the element is not found in the array or the searched element is at index "0". But still there is the deciding factor - the Boolean output.
 
- Murali
Message 7 of 10
(3,143 Views)
That would break a lot of existing code:
Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
Nederlandse LabVIEW user groep www.lvug.nl
My LabVIEW Ideas

LabVIEW, programming like it should be!
Message 8 of 10
(3,139 Views)
Actually, I hear that if you wire a negative number the loop runs backwards...  Smiley Very Happy

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
Message 9 of 10
(3,077 Views)


mikeporter wrote:
Actually, I hear that if you wire a negative number the loop runs backwards...  Smiley Very Happy

A much more useful feature is to select the spin direction of while loops. I use that all the time! (also seems often slightly faster). 😄
 
 
Of course you might need to change it when you travel to e.g. Australia or elsewhere on the southern hemisphere..


Message Edited by altenbach on 06-16-2008 10:51 PM
Message 10 of 10
(3,064 Views)