Avoid Infinite Loops

If you don't design your loop correctly, you can get an infinite loop — a loop that never ends. You will not be able to stop the procedure by using the Escape key. The following procedure causes the loop to execute endlessly because the programmer forgot to include the test condition:

Sub SayHello() Do

MsgBox "Hello." Loop End Sub

To stop the execution of the infinite loop, you must press Ctrl + Break. When Visual Basic displays the message box "Code execution has been interrupted," click End to end the procedure.

0 0

Post a comment