The Daily CLAD

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

Re: For loops, Shift Registers and Auto-Indexing

SercoSteveB
Active Participant

Steve - Maybe a little complex for a CLAD question, it combines some classic CLAD concepts.

 

What is Numeric Value Out after the following has executed?

 

 Daily CLAD #8.png

 

a)    24

b)    A 1D Array with contents {0,8,16,24}

c)    A 1D Array with contents {0,2,4}

d)    A 2D Array with contents {{0,2,4},{0,2,4},{0,2,4},{0,2,4}}

Comments
SercoSteveB
Active Participant

Answer B:

At run-time:

For each of the four iterations of the outer loop, the iteration count, from the outer loop, is used to initialise the shift register of the inner loop.  The table below shows the values in the shift register for each iteration of the inner and outer loops.

Outer For loop Iteration terminal value

0

1

2

3

Shift Register value after first iteration of the inner loop

0

2

4

6

Shift Register value after second iteration of the inner loop

0

4

8

12

Shift Register value after third iteration of the inner loop

0

8

16

24

It is only when the inner loop completes, following its’ third iteration; that the value in the shift register (0, 8, 16, 24) is passed to the auto-indexed output tunnel of the outer loop and auto-indexed into an array for passing to Numeric Value Out on completion of the outer loop.

MaciekP
Member

It's enough to figure out how the Numeric Value Out should look like i guess:

  • Autoindexing enabled in the outer loop only - 1D array
  • Iteration count = 4 - 1D array with 4 elements

thus answer B of course.

eleshrudra
Member

B

R.Elesh
Andreas.Bernau
Member

B
For me I had to calculate for i=0 and i=1 so output array starts with 0 and 8 and has to have 4 elements.
Maybe there are faster approaches to solve this...

Oh yes, of course, no need to calculate. Thank you MaciekP

sac0071
Member

B

N.UdhayaKamali
Member

B

moh3li
Member

b

ersmt444
Member

Image broken

Blake.N
Member

B, effectively multiplying each iteration (0,1,2,3) by (2x2x2)

skian
Member

B