2

I iterate over a huge ds_list and want to know if the condition (in this case the size of the ds_list) will be calculated after every loop again and again (which would be bad for the performance). In that case I would store the result in a temporary variable.

for (var i = 0; i < ds_list_size(huge_list); i++) {
    // doing something
}
Christoph S.
  • 585
  • 3
  • 16

1 Answers1

2

A for loop will run the "condition" expression on each iteration, meaning that it can be beneficial to store the list size in a temporary variable if it will not change during the loop. You may verify this by using a script with a show_debug_message call in it as a condition.

YellowAfterlife
  • 2,967
  • 1
  • 16
  • 24