While loop in codeblocks

Hi guys,

I am creating a script and I need a while loop in a code block
I don’t know how to do that but I have a bit knowledge of coding so I reached the following loop;

Can anyone please help me with the syntax and the wrong phrases

Thank you

Have you read the Dynamo DesignScript documentation: Dynamo DesignScript Learning Resources

I would start there and create a really simple while loop then scale it up. Just reviewing your code (also, please post a copy of your code as you’ll get more answers):

  1. LI instantiation appears to be wrong, use LI={};
  2. P=List.AddItemToEnd(P,LI) is also wrong as you are assigning a list object to P (which is a Polycurve). You should be adding this to LI
  3. Returning LI with nothing assigned to it will return…nothing!

Thank you @Thomas_Mahon for replying :slight_smile:

I had a look at the first pdf before , and the second one is very helpful thank you

I fixed these problems you mentioned but I still receive error in the codeblock

this is my script:

def ST(N,L,P1,P2,S,V1,V2)
{
return=[Imperative]
{
n=0;
LI={};
while(n<N)
{
PT1=P1.Translate(V1,(L[n]-1)*S);
PT2=P1.Translate(V1,(L[n+1]-1)*S);
PT3=P2.Translate(V2,(L[n]-1)*S);
PT4=P2.Translate(V2,(L[n+1]-1)*S);
L1=Line.ByStartPointEndPoint(PT1,PT2);
L2=Line.ByStartPointEndPoint(PT2,PT3);
L3=Line.ByStartPointEndPoint(PT3,PT4);
L4=Line.ByStartPointEndPoint(PT4,PT1);
P=PolyCurve.ByJoinedCurves({L1,L2,L3,L4});
LI=List.AddItemToEnd(P,LI);

n=n+2;
}
return=LI;
}};

It seems that I cannot use L and an input parameter when I changed it to LL it worked perfectly but I don’t know why!!

Anyway thank you :slight_smile: