【问题标题】:For Each...Next with or without element differenceFor Each...Next 有或没有元素差异
【发布时间】:2017-04-27 10:46:55
【问题描述】:

For Each 循环中,如果我们在Next 语句之后添加有问题的元素,会有区别吗?

也就是说,下面这两种有效方式有什么区别?

For Each Element in MyCollection
'...code
Next

For Each Element in MyCollection
'...code
Next Element

【问题讨论】:

  • 据我所知,这纯粹是为了更容易阅读和跟踪您的嵌套。上面没有太大区别,但在有很多嵌套循环的代码中它确实有帮助。 (和缩进一样)
  • 一个快速的谷歌会显示这个答案。 msdn.microsoft.com/en-us/library/5ebk1751.aspxYou can optionally specify element in the Next statement. This improves the readability of your program, especially if you have nested For Each loops. You must specify the same variable as the one that appears in the corresponding For Each statement.
  • 好的,谢谢你的信息!

标签: vba excel loops foreach


【解决方案1】:

添加变量名是可选的。虽然我建议您选择您/您的组织首选的方式并始终坚持下去

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-26
    • 2016-08-25
    • 1970-01-01
    • 2021-10-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多