VB.NET-如何移至下一个项目“每个循环"? [英] VB.NET - How to move to next item a For Each Loop?

查看:193
本文介绍了VB.NET-如何移至下一个项目“每个循环"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有类似Exit For的语句,除了没有退出循环,它只是移至下一项.

Is there a statment like Exit For, except instead of exiting the loop it just moves to the next item.

例如:

For Each I As Item In Items

    If I = x Then 
        ' Move to next item
    End If

    ' Do something

Next

我知道可以简单地将Else添加到If语句中,因此其内容如下:

I know could simply add an Else to the If statement so it would read as follows:

For Each I As Item In Items

    If I = x Then 
        ' Move to next item
    Else
        ' Do something
    End If

Next

只是想知道是否有一种方法可以跳到Items列表中的下一项.我敢肯定,大多数人都会正确地问为什么不只使用Else语句,而是包装"Do Something"代码对我来说似乎不太可读.尤其是当有更多代码时.

Just wondering if there is a way to jump to the next item in the Items list. I'm sure most will properly be asking why not just use the Else statement, but to me wrapping the "Do Something" code seems to be less readable. Especially when there is a lot more code.

推荐答案

For Each I As Item In Items
    If I = x Then Continue For

    ' Do something
Next

这篇关于VB.NET-如何移至下一个项目“每个循环"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆