VBA-如何有条件地跳过for循环迭代 [英] VBA - how to conditionally skip a for loop iteration
本文介绍了VBA-如何有条件地跳过for循环迭代的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在数组上有一个for循环.我想做的是在循环中测试特定条件,如果为true,则跳到下一个迭代:
I have a for loop over an array. What I want to do is test for a certain condition in the loop and skip to the next iteration if true:
For i = LBound(Schedule, 1) To UBound(Schedule, 1)
If (Schedule(i, 1) < ReferenceDate) Then
PrevCouponIndex = i
Continue '*** THIS LINE DOESN'T COMPILE, nor does "Next"
End If
DF = Application.Run("SomeFunction"....)
PV = PV + (DF * Coupon / CouponFrequency)
Next
我知道我可以做到:
If (Schedule(i, 1) < ReferenceDate) Then Continue For
但是我希望能够在PrevCouponIndex变量中记录i的最后一个值.
but I want to be able to record the last value of i in the PrevCouponIndex variable.
有什么想法吗?
谢谢
推荐答案
您难道不就做这样简单的事情吗?
Couldn't you just do something simple like this?
For i = LBound(Schedule, 1) To UBound(Schedule, 1)
If (Schedule(i, 1) < ReferenceDate) Then
PrevCouponIndex = i
Else
DF = Application.Run("SomeFunction"....)
PV = PV + (DF * Coupon / CouponFrequency)
End If
Next
这篇关于VBA-如何有条件地跳过for循环迭代的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文