Forum Discussion
List Generate , how it iterates
- 1 year ago
As I wrote above: in that example you are never resetting y. So once y becomes greater than 10, y always remains greater than 10.
Therefore z will always be set to alist{x}
In your non-working snippet, your sequence will not repeat because you never reset "y". So once y>10 = true, it will always be >10 and z will always return alist{x}
let
alist = {3} & List.Repeat({2} , 25)
in
List.Generate( ()=> [ x = 0 , y = alist{0} ,z = 0 ] ,
each [x] < List.Count(alist) ,
each [ x = [x] + 1,
y = [y] + alist{x} ,
z = if y > 10
then alist{x}
else y ] ,
each [z] )
Try:
let
alist = {3} & List.Repeat({2} , 25)
in
List.Generate( ()=> [ x = 0 , y = alist{0} ,z = 0 ] ,
each [x] < List.Count(alist) ,
each [x = [x] + 1,
y = if [y] + alist{x} > 10
then alist{x}
else [y] + alist{x},
z = y ] ,
each [z] )
although you don't really need z at all
let
alist = {3} & List.Repeat({2} , 25)
in
List.Generate( ()=> [ x = 0 , y = alist{0}] ,
each [x] < List.Count(alist) ,
each [x = [x] + 1,
y = if [y] + alist{x} > 10
then alist{x}
else [y]+alist{x}] ,
each [y] )
I still don't see why the condition does not kick in as expected the third example,
so this works y = if [y] + alist{x} > 10 then alist{x} else [y] + alist{x} ] works,
but if [y] + alist{x} is declared as a variabel y
and then ; if z = if y > 10 then alistt{x} it returns a different incorrect restult?
that's the question, I not bothered about solving it just why the two operate differently
- ronrsnfld1 year agoSuper User
As I wrote above: in that example you are never resetting y. So once y becomes greater than 10, y always remains greater than 10.
Therefore z will always be set to alist{x}