Breaking/exit nested for in vb.net

后端 未结 6 1567
栀梦
栀梦 2020-11-29 00:15

How do I get out of nested for or loop in vb.net?

I tried using exit for but it jumped or breaked only one for loop only.

How can I make it for the following

6条回答
  •  广开言路
    2020-11-29 00:28

    I've experimented with typing "exit for" a few times and noticed it worked and VB didn't yell at me. It's an option I guess but it just looked bad.

    I think the best option is similar to that shared by Tobias. Just put your code in a function and have it return when you want to break out of your loops. Looks cleaner too.

    For Each item In itemlist
        For Each item1 In itemlist1
            If item1 = item Then
                Return item1
            End If
        Next
    Next
    

提交回复
热议问题