Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

what are benefits of using for loop for creating objects and just creating them.

what are benefits of using for loop for creating objects and just creating them.

Anonymous
Not applicable
942 Views
5 Replies
Message 1 of 6

what are benefits of using for loop for creating objects and just creating them.

Anonymous
Not applicable

Hello,

 

aside from compactness in your code, is there any other benefits to creating multiple similar objects using a for loop compared to creating them line by line?

 

thank you.

 

 

0 Likes
Accepted solutions (1)
943 Views
5 Replies
Replies (5)
Message 2 of 6

miauuuu
Collaborator
Collaborator

What about if you want to create 1000 objects? You will write 1000 lines of code for this? And if you have to edit this code later, you will edit 1000 lines one by one(let say that each obejct have a unique "property")? 10 000 objects?

https://miauu-maxscript.com/
0 Likes
Message 3 of 6

Anonymous
Not applicable

I understand your points, but I was asking about comparing performance or speed of execution when running the for loop verses no for loop, nothing about the mechanics or time of writing it out in the first place or how many objects I am creating.

 

 

0 Likes
Message 4 of 6

Swordslayer
Advisor
Advisor
Accepted solution

For loop is slower in general case, of course, but unless we're talking about tens of thousands of executions, you won't be able to measure that. You will spend much more time maintaining the code, however.

0 Likes
Message 5 of 6

denisT.MaxDoctor
Advisor
Advisor

@Anonymous wrote:

For loop is slower in general case, of course...


why do you think the loop is slower? from the parser point of view "loop" probably faster than several lines of code, which used only one in the loop's body

0 Likes
Message 6 of 6

Swordslayer
Advisor
Advisor

If I had to guess, I'd say it's probably because it creates and destroys new scope. A real-world example of the speed benefit of loop unrolling is for example this one.

0 Likes