【问题标题】:Changing end integer of a loop within said loop在所述循环内更改循环的结束整数
【发布时间】:2019-11-10 18:28:29
【问题描述】:

我正在处理一些代码,我正在尝试修改所述循环中循环的结束整数(如标题中所述)

所以它看起来像这样

dim x as integer

For i=0 to x
    if (some conditions) then
        x=x+1
    End if
Next 

但它似乎不起作用,看起来循环正在使用 x 的静态值而不是动态值。

有没有办法在不使用exit for 并重新开始循环的情况下更新循环的结束整数?

谢谢

【问题讨论】:

标签: vb.net loops for-loop


【解决方案1】:

您可以使用 While 循环。

dim x as integer
Dim i as Integer = 0

While i <= x
    if (some conditions) then
        x=x+1
    End if
End While 

【讨论】:

  • 谢谢,我已经习惯了只使用 for 循环,以至于我什至没有想到使用另一种循环...
猜你喜欢
  • 2021-08-15
  • 1970-01-01
  • 2021-11-09
  • 1970-01-01
  • 2020-05-18
  • 1970-01-01
  • 2011-02-19
  • 1970-01-01
  • 2019-03-17
相关资源
最近更新 更多