Vb.net 对于循环,如何跳过迭代

Vb.net 对于循环,如何跳过迭代,vb.net,Vb.net,我试图找出如何跳过For循环的迭代。我做了一些研究,发现我可以使用继续,但这并不能解决我的问题。下面是我想做的一个例子: For i As Long = 1 to 7 Step 1 If (i= 2, 5 and 7) Then 'perform this action Else 'perform other action. End If Next i 我计算出了以下内容,但不幸的是,它适用于如何将if子句重新设置为 If (i <

我试图找出如何跳过
For
循环的迭代。我做了一些研究,发现我可以使用继续,但这并不能解决我的问题。下面是我想做的一个例子:

For i As Long = 1 to 7 Step 1
    If (i= 2, 5 and 7) Then
        'perform this action
    Else
        'perform other action.
    End If
Next i

我计算出了以下内容,但不幸的是,它适用于
如何将
if
子句重新设置为

If (i <= 2) or (i = 5) or ( i =7)  Then
   ...

If(i
If(i)请在代码文件顶部设置Option Strict,或在项目的属性中设置它。您的If条件不应编译,因为它需要布尔表达式。非常好,正是我所需要的。
If (i <= 2) or (i = 5) or ( i =7)  Then
   ...
  For i As Long = 1 To 7 Step 1
    If (i <= 2) OR (i = 5) OR (i = 7) Then
        strRange = ("A:D")
    Else
        strRange = ("A:A")
    End If

    xlRefSheets = ClientSheets(i)
    With xlRefSheets
        .Cells.EntireColumn.AutoFit()
        .Range(strRange).EntireColumn.Hidden = True
    End With
  Next i