Level List in CodeBlock Loop

HI,
I have List and CodeBlock, When one List ,can success the Loop,But Level List ,return Empty List,I don’t know how can i do, Please help me,Thanks.


hi there, what is the purpose of your code block actually? it should be really easy to fix, but in order to be able to help you, we should know what you are trying to achieve :slight_smile:

1 Like

Example,one list can success the for loop,Level list can’t success for loop,it return Empty,but i want two sum list.

1671673707776

Hello,
here is a possibility

code block definition:

def sum_cum(_List: var[])
{
Somme=[Imperative]
{
	s[];
	s[0]=_List[0];
for (i in 1..DSCore.List.Count(_List)-1)
	{
	s[i]=s[i-1]+_List[i];
	}
return = s;
}
return = Somme;
};

Cordially
christian.stan

Thank again christian.stan ! That’s it what i want !
I unfamiliar Code Block Loop,If i want rewrie that’s Code Block how can i do?


Thanks in advance.

1 Like

Hello, here is an answer, I admit that I have trouble understanding what you are trying to achieve via this code block
(Afterwards, I’m not a strong person)

code block definition:

def sum_born(a:var[],b:int)
{
res= [Imperative]
{
	newList=[];
	sum=0;
	for (i in a)
	{
	sum = sum+i;
		if (sum>b)
		{
			newList=DSCore.List.Flatten([newList,sum-i]);
			sum=i;
		}
		else
		{
			sum=sum;
		}
	}
	return newList;
}
return res;
};

Cordially
christian.stan

1 Like

Extremely grateful christian.stan,That’s it what i want !

1 Like