The Daily CLAD

Community Browser
cancel
Showing results for 
Search instead for 
Did you mean: 

Re: For loop iteration control #6

SercoSteveB
Active Participant

What are the values of A, B, C & D after the following has executed?

Daily CLAD #11 Default Values.png

 

a)    A=TRUE, B=SercoSteveB, C=1, D=1D Array containing {2}

b)    A=FALSE, B=SercoSteveB, C=0, D=1D Array containing {2}

c)    A=TRUE, B=<empty string>, C=1, D=<empty 1D array>

d)    A=FALSE, B=<empty string>, C=0, D=<empty 1D array>

 

NOTE:  <empty string> means the string is empty (i.e. string length = 0) not a string containing "<empty string>".  Similarly for <empty array> (array size = 0).

Comments
SercoSteveB
Active Participant

Answer 😧

At run-time:

The For loop will iterate zero times; as defined by the size (zero elements) of the auto-indexed input array.  On completion of zero iterations; the For loop will pass default values to its output tunnels. 

The default values for the data types in the example are shown:

Boolean = FALSE

String = <empty string>

Numeric = 0

Array = <empty array>

labnoob
Active Participant

good one, I built this but was surpised to see my asnwer was A. Then I noticed that I had entetred a value of 0 in the array constant, creating one element appear in the array. 🙂

SercoSteveB
Active Participant

Hi labnoob (cool name).  Zero iterations and the resulting output of default values is only something I began to appreciate after at least five years doing LabVIEW, lucky its not something that happens everyday.

A.Rohde
Active Participant

This is a nice example Steve

So guys:

Remember the shift register when you wire an error cluster into a for-loop that has the possibility of executing 0 times! Otherwise you will risk losing the error.

Using a shift register will use the same memory allocation for the input - and output terminal and thereby allowing the error to pass through when the for loop doesn't execute.

SercoSteveB
Active Participant

Yep,  Error Clusters are probably the first place I ever noticed things going awry. One other springs to mind; if you open your file outside the loop and want to close it after the loop is completes, the file reference is lost if you don't use a shift register and the loop does not iterate.

mini09
Active Participant

Here the N terminal is not connected y LabVIEW doesn through error?

A.Rohde
Active Participant

Hi gnshmrthy

The for loop executes at set number of times. The iteration number is the lowest "wired" number to the for-loop. In this example an array is wired to the for loop with the size 0, this is the lowest number connected to the for loop and thereby it will execute 0 times. So the iteration count N is not needed in a for-loop as long as you have an array as input and is using the auto indexed tunnel. Therefore you will not get an error. But LabVIEW will never run the code inside the for-loop and therefore the indicaters will be updated with the default value of each data type.

mini09
Active Participant

that was quite nice explaination Mr.Rohde.... here the for loop never runs codes inside them and the default value is displayed am i rit...

A.Rohde
Active Participant

That is correct.

GayatriT
Member

Ans D:)

beautyandbrains
Member

D 🙂

eleshrudra
Member

d

R.Elesh
Andreas.Bernau
Member

D

sac0071
Member

D

ersmt444
Member

Image broken

Blake.N
Member

Good one, fell right into the trap. Now I know 🙂

skian
Member

D