是否有相当于 C# 的“继续”的 VB?和“打破”声明?

发布于 2024-08-04 06:24:18 字数 181 浏览 3 评论 0原文

为了方便讨论,我怎样才能在 VB 中做到这一点?

foreach foo in bar
{
   if (foo == null)
       break;

   if (foo = "sample")
       continue;

   // More code
   //...
}

For sake of argument, how could I do this in VB?

foreach foo in bar
{
   if (foo == null)
       break;

   if (foo = "sample")
       continue;

   // More code
   //...
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

请爱~陌生人 2024-08-11 06:24:18

-- 编辑:

自从我回答以来,你已经改变了你的问题,但我会在这里留下我的答案;我怀疑 VB.NET 程序员会向您展示如何实现这样的循环。我不想因为尝试...而伤害我可怜的 C# 编译器的感情

——旧的回应:

我相信有

Continue While
Continue For

并且

Exit While
Exit For

-- Edit:

You've changed your question since I've answered, but I'll leave my answer here; I suspect a VB.NET programmer will show you how to implement such a loop. I don't want to hurt my poor C# compilers feelings by trying...

-- Old response:

I believe there is

Continue While
Continue For

and

Exit While
Exit For
雨的味道风的声音 2024-08-11 06:24:18

我认为 VB.NET 示例将来可能会有所帮助:

Sub breakTest()
    For i = 0 To 10
        If (i = 5) Then
            Exit For
        End If
        Console.WriteLine(i)
    Next
    For i = 0 To 10
        If (i = 5) Then
            Continue For
        End If
        Console.WriteLine(i)
    Next
End Sub

break 的输出:

0
1
2
3
4

以及 continue 的输出:

0
1
2
3
4
6
7
8
9
10

I thought a VB.NET example may help in the future:

Sub breakTest()
    For i = 0 To 10
        If (i = 5) Then
            Exit For
        End If
        Console.WriteLine(i)
    Next
    For i = 0 To 10
        If (i = 5) Then
            Continue For
        End If
        Console.WriteLine(i)
    Next
End Sub

The output for break:

0
1
2
3
4

And for continue:

0
1
2
3
4
6
7
8
9
10
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文