Why doesn't this for loop process the full data set?

前端 未结 3 1222
轮回少年
轮回少年 2021-01-19 06:04

Background

I have a spreadsheet of ticket allocations for an event. On each row of the spreadsheet is a name and the number of tickets allocated.

3条回答
  •  时光说笑
    2021-01-19 06:30

    This is by design in VB. The limit of a for loop is calculated only once and saved in a temporary variable, just before the start of the loop. So if you change the value of the variables from which it calculates the limit, the temp variable is not affected. While this has the unexpected effect you encountered, it has the plus that the limit is only calculated once, so any methods used in this calculation is only entered once, potentially doing the loop faster.

提交回复
热议问题