Which loop type is lag friendly?

When scripting there are varies of loop type to use. They all have different properties. I commonly use while loops, and I use them too much. And that’s bad for the game because they run around 30 hertz or more if not used carefully. I wonder if all other loops do the same.

Which Loop Type is Lag Friendly?
  • While Loops
  • For Loops
  • Repeat Loops
  • Other(Explain Which One If Possible)

0 voters

All these loops have different uses. None are really better for performance than another.

While loops are used for keeping a condition running. For is for iterating through an array, table or numbers. Repeat is usually used for yielding a script.

4 Likes

I have a poor laptop so I’m laggy for everything. I notice I’m less laggy with the While Loops.

In my opinion it depends on what they do. If you think you ain’t going to need the while loop anymore just break it. for loop is very different, in my opinion is not a loop by the way. I use repeat loops a lot. Well, as I said I think the lag comes when executing expensive code really fast. (Sorry if I didn’t explained myself well)

1 Like

Loops have the same performance AFAIK. The difference is the use cases of situation.

Want to loop forever? While loops.
Want to loop for a certain amount of times? For loops.
Want to loop until something happens? Repeat-until loops.

It’s not about performance, it’s about the situation you are using the loops in.

2 Likes

Round 5 of “none are better than the other”.

They’re different loops and they have different purposes. Performance doesn’t depend on the type of loop you’re using necessarily, it depends on what you’re doing in each iteration. If your code is expensive and you’re running that in quick succession, expect lag.

Use some of Studio’s debugging tools to help you determine the performance of each iteration.

5 Likes