Conditional statements inside a nested for loop

I’m trying out ways to fit a conditional statement into a nested for loop.

In the trial example I want to only multiply the content of the first 4 sub-lists with 10, leaving the rest as it is.

The code works only when the IF statement is not in it, what am I doing wrong?
Or is there a different way to use conditional statements inside a for loop?

Any help and pointers are much appreciated.

@harry_zhao

maybe you can reduce your codeblock to

Try this

input;
[Imperative]
{
    out = [];
    for (i in input)
    {
        for(j in 0..3)  // index counter
        {
            i[j] = i[j] * 10;
        }
        out = List.AddItemToEnd(i, out);
    }
    return out;
};
1 Like

Thanks for the reply, but for my project I think I need to enumerate the list, to place a conditional statement on the index, is that possible in Design Script?

Is there a particular reason you want to use designscript? It’d be easy to use a Python node.

Here’s what I’m doing.

I need to place tiles on a Chinese hip roof, I want to do it with adaptive family with 4 adaptive points.

To do that I need to sift out the lines with divisions that are shorter than the central lines.
I’m more comfortable in the Dynamo environment, hence my preference of using design script.

I’m aware that you can probably do it with just nodes, but the next step might involve me sifting out the distance of the last point to see if I can fit an entire tile in that space.

So using design script is a middle ground for me not going into Python.

I think it is possible
Use for (j in 0..List.Count(i)-1) and then

{
    if (<test>)
    {
        i[j] = i[j] * <function>;
    }
}

As you are working with an existing list you don’t have to pass to a collecting list

1 Like

It’s often possible to simplify the logic by separating steps in Dynamo. No need for an Imperative statement here when you can write a straight conditional.

2 Likes