The Daily CLAD

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

Re: CLAD2017 - Fundamentals - Array Crunching #2 (Devilish)

SercoSteveB
Active Participant

What are the contents of Numeric Array Out following execution of the VI?

 

In Range and Coerce 2.png

 

In Range and Coerce 2 Answers.png

Comments
SPK91
Member

A

Priya16
Member

C

Because in range and coerce would compare the first element of second row also. Here second row first element is 6 (not in range) so it returns 0 to the second row. 

AUlikyan_ANEL
Member

C

crossrulz
Knight of NI

C

 

The second is not added at all.  But the third, empty, row is added since the Index Array will return the default value (0), which does satisfy the In Range And Coerce.  But since all rows must be the same size, the new row will be all 0.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
alexderjuengere
Active Participant

I would have said A, but this is  a While Loop not a For Loop

array-crunching.png

 

nice one!

Ganesh_anbu
Member

hello friend,

     the explanation you have given is having input array 3 rows or 2 rows ??? 

 

SercoSteveB
Active Participant

Hi Alex, yep it is a bit devilish (but that is how I roll).  Using a DO-WHILE instead of a WHILE-DO. No such problem with the For Loop DO.

Bcortes
NI Employee (retired)

The answer is C, since the while loop always executes its code once after evaluating the loop condition even though it is T. Here is the explanation:Daily CLAD 5 Feb 2018.png

anodeanna
Member

Just to clarify, since somehow I seem to have overlooked this crucial difference between while and for loops--

 

A for loop with a conditional terminal will stop execution (when the condition is met) immediately, mid-iteration, whereas a while loop will recognize that the condition is met but finish the current iteration, and then stop?

 

And side note: The Daily CLAD is an amazing resource. Having taken the CLAD before and failed because I was studying for the pre-2017 version (due to misinformation provided by my professor), I've learned a lot since finding this blog. 

SercoSteveB
Active Participant

Hi anodeanna

 

I would say the execution of FOR and WHILE loops is the same around the evaluation of the STOP Condition.

Both the FOR and WHILE will complete execution of the code for the current iteration (whatever is inside the looping structure) before checking the STOP condition. 

NOTE: The FOR Loop may also stop due to the number of specified iterations being completed or by an auto indexing input tunnel reaching an empty array element.

 

Hope this helps

 

Steve 

anodeanna
Member

Thanks for the reply, Steve.

If that is the case (that both FOR and WHILE will complete the current iteration before checking the stop condition), why is it that in alex's code snippet, that the result of the for loop does not include the row of zeros?

crossrulz
Knight of NI

Because the value wired to the N on the FOR loop limits how many iterations the loop will perform.  But to do that FOR loop properly, the array should be autoindexed, which would eliminate the need for the first Index Array.  The FOR loop is smart enough that it will only iterate the number of rows in the array.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
anodeanna
Member

Duh! For some reason I was thinking that the value wired to the count terminal of the FOR loop was large enough that the stop condition would return T first, before N was reached.

 

Obviously, the value wired to N is 2, meaning that the FOR loop will stop after i reaches a value of 1. 

 

It's a miracle how something can make sense when you look at it in LabVIEW...

 

Array Crunching Devilish.png

Hesham_Hassanein
Member

Why array element 5 is encluded, shouldn't it be only till element 4, because element 5 is out of range?

 

Thanks

crossrulz
Knight of NI

Hesham_Hassanein,

The first Array Index is getting the row.  The comparison is being done only on the first element of the row.  So your array element 5 is never checked.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
rak84
Member

c

istan0227
Member

C