如何跳到下一行没有在vb.net中浏览整个for..loop

时间:2013-09-18 03:49:01

标签: vb.net for-loop dataset

我想跳到下面的陈述中的下一行

For iRow = 0 To dsDiscnt.Tables(0).Rows.Count - 1
     rowDiscnt = dsDiscnt.Tables(0).Rows(iRow)

     If rowdiscnt.Item("x") = "S" Then
         'skip to next row
     Else
         'continue loop
     End If

'do something...
Next

如何跳过下一行没有经过整个循环?

2 个答案:

答案 0 :(得分:1)

Continue For是您需要的声明,如下所示:

For iRow = 0 To dsDiscnt.Tables(0).Rows.Count - 1
    rowDiscnt = dsDiscnt.Tables(0).Rows(iRow)

    If rowdiscnt.Item("x") = "S" Then
        ' Skip to next iteration of For loop
        Continue For
    Else
        ' Keep doing work in this iteration of the For loop
    End If

    'do something...
Next

答案 1 :(得分:0)

For iRow = 0 To dsDiscnt.Tables(0).Rows.Count - 1
     rowDiscnt = dsDiscnt.Tables(0).Rows(iRow)

     If rowdiscnt.Item("x") = "S" Then
         break;//'skip to next row
     Else
         'continue loop
     End If

'do something...
Next

修改

For iRow = 0 To dsDiscnt.Tables(0).Rows.Count - 1
     rowDiscnt = dsDiscnt.Tables(0).Rows(iRow)

     If rowdiscnt.Item("x") = "S" Then
         Continue For;//'skip to next row
     Else
         'continue loop
     End If

'do something...
Next