While loop in codeblocks

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!