Is the condition in a for loop evaluated each iteration?

前端 未结 4 510
忘了有多久
忘了有多久 2020-12-17 08:02

When you do stuff like:

for (int i = 0; i < collection.Count; ++i )

is collection.Count called on every iteration?

Would the res

4条回答
  •  醉酒成梦
    2020-12-17 08:34

    Yes count is checked at every call from the first iteration after the initialization of i to the last iteration where the check fails and the for loop is exited. You can modify the collections count if you want but realize you could end up in an endless loop.

提交回复
热议问题