Efficently using while loops

so basically, which would be better


individual scripts containing while loops or a master script containing one while loop?

slight clarification: there would be many many objects and they all would do the same thing

Technically, one loop is more efficient and is more “predictable”, assuming your loops are similar in behavior.

1 Like

One loop is more resource efficient, however, if you aren’t going to use a lot of while loops at the same time and they do not run for a long time, you can use multiple as it would be a bit more convenient for you to code.

Which would be better is whichever one is easier to write. The difference between them is going to be negligible. But from a pure instruction efficiency a single loop would be better as you potentially check the conditions less and do less jumps. (In languages where you have more control over memory like C this is less straightforward)

But honestly, this won’t be what makes or breaks your system. Ever. If you run into performance issues, you will need to reduce the amount of objects you process, not just shave off a handful of instructions.

So just write whatever is easier to read and maintain. This will be different depending on style and the specific problem you are solving.

1 Like

a master script will be better its also good to optimize your code inside the loop