Infinite Loop in Visual Basic .NET

Tags: VB.NET, VB 2008, VB 2010, VB 2012, VB 2013

This lesson describes the Infinite Loops in Visual Basic .NET

When you work with loops, you can easily create an infinite loop. This is a loop that is never finishing. This logic error is one of the most difficult to find and troubleshoot so you should be very careful when you work with loops to not end up with loops whose exit condition can never be satisfied.

Tip: Whenever you suspect a program has fallen into an infinite loop, just force the program to stop using Debug menu - Stop Debuging or use Ctrl + Shift + A in your Visual Studio.
This will stop the program immediately.

The following code is a classic example of an infinite loop and will not stop:

    Dim counter As Integer = 10
    Do While counter > 0
        counter += 1 ' + instead - 
        'Do something
    ' this loop just keeps going forever as counter is always greater than 0             

Previous Lesson | Next Lesson

Share This

Home | About | Contact | Privacy Policy

Copyright 2018 - All Rights Reserved.