Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Prodentim Probiotics Specially Designed For The Health Of Your Teeth And Gums

Instant Grammar Checker - Correct all grammar errors and enhance your writing

Teach Your Child To Read

Powerful WordPress hosting for WordPress professionals

Disclosure: My content contains affiliate links.

31,111 questions

40,781 answers

573 users

How to break out of nested for loops in VB.NET

4 Answers

0 votes
Imports System

Public Class Program
	Public Shared Sub Main()
        Dim _stop As Boolean = False
        Dim i As Integer = 1

        While i <= 30 AndAlso Not _stop
            For j As Integer = 0 To 5 - 1 
                If i = 4 Then
                    _stop = True
                    Exit For
                End If
                Console.Write(j & " ")
            Next
            Console.WriteLine()
            i += 1
        End While

        Console.WriteLine("After loops")
    End Sub
End Class

 

 
 
' run:
'
' 0 1 2 3 4 
' 0 1 2 3 4 
' 0 1 2 3 4 
' 
' After loops
'

 





answered Sep 7, 2022 by avibootz
0 votes
Imports System

Public Class Program
	Public Shared Sub Main()
        For i As Integer = 1 To 30
            For j As Integer = 0 To 5 - 1
                If i = 4 Then
                    GoTo ENDLOOPS
                End If
                Console.Write(j & " ")
            Next
            Console.WriteLine()
        Next

ENDLOOPS:
        Console.WriteLine(Environment.NewLine & "After loops")
    End Sub
End Class


 

 
 
' run:
'
' 0 1 2 3 4 
' 0 1 2 3 4 
' 0 1 2 3 4 
' 
' After loops
'

 





answered Sep 7, 2022 by avibootz
0 votes
Imports System

Public Class Program
	Public Shared Sub Main()
        Do
			For i As Integer = 1 To 30
				For j As Integer = 0 To 5 - 1
					If i = 4 Then
						Exit Do
					End If
					Console.Write(j & " ")
				Next
				Console.WriteLine()
			Next
		Loop While False
		
        Console.WriteLine(Environment.NewLine & "After loops")
    End Sub
End Class


 

 
 
' run:
'
' 0 1 2 3 4 
' 0 1 2 3 4 
' 0 1 2 3 4 
' 
' After loops
'

 





answered Sep 7, 2022 by avibootz
0 votes
Imports System

Public Class Program
	Public Shared Sub Main()
         Try
            For i As Integer = 1 To 30
                For j As Integer = 0 To 5 - 1
                    If i = 4 Then Throw New Exception("")
                    Console.Write(j & " ")
                Next
                Console.WriteLine()
            Next
        Catch
            Console.WriteLine("")
        End Try

        Console.WriteLine("After loops")
    End Sub
End Class



 

 
 
' run:
'
' 0 1 2 3 4 
' 0 1 2 3 4 
' 0 1 2 3 4 
' 
' After loops
'

 





answered Sep 7, 2022 by avibootz

Related questions

3 answers 69 views
3 answers 51 views
3 answers 56 views
2 answers 64 views
3 answers 69 views
...