> ## Content Index
> Fetch the complete content index at: https://nolongerset.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# The Danger of Do Loops
- URL: https://nolongerset.com/the-danger-of-do-loops/
- Published: 2021-02-27T01:14:33.000Z
- Updated: 2026-05-08T13:06:09.000Z
- Description: If you're going to write a Do Loop, don't forget to update whatever it is you're using to break out of said loop. And, oh yeah, save before testing!
- Author: Mike Wolfe
- Tags: Basic, #Import 2026-05-20 02:59

When using "[Do Loops](https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/whilewend-statement)"--such as Do While ... Loops, Do ... Until Loops, or (the syntactically superfluous) [While...Wend](https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/whilewend-statement) Loops--you need to be careful to avoid accidentally getting stuck in an infinite loop. 

[Francesco](https://twitter.com/francescofoti)\--whose "Looping by Month" solution I referenced in yesterday's [article](https://nolongerset.com/looping-by-month-loop-until-with-dateadd/)\--accidentally bumped into this himself when he was testing his function:

> No problem, go ahead. Can't think of any other name. I should mention that the first time I ran it, I forgot to add the line that increments the date; was stuck in an unstoppable endless loop. The For loop "protects" against that. So maybe not the safest approach!
> 
> — francesco (@francescofoti) [February 24, 2021](https://twitter.com/francescofoti/status/1364584609586044928?ref%5Fsrc=twsrc%5Etfw)

I appreciate the honesty, Francesco! 

### Infinite loop fallout

Coincidentally, I did the same thing later that day while working on an entirely different piece of code. In fact, it was the sample code I was writing for a different [article](https://nolongerset.com/looping-by-month-lookup-table/) about using a monthly lookup table to loop by month. I had forgotten to add the `.MoveNext` line before I tested the function for the first time.

To make matters worse, there was nothing in the loop--such as a call to [DoEvents](https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/doevents-function)\--that was yielding any processor time. That meant that it was impossible for me to break into my infinite loop.

### Before writing an infinite loop and forcing yourself to kill the msaccess.exe process...SAVE YOUR CODE

Luckily for me, the only unsaved changes I had were to the looping code itself. I took a screenshot of the code (now grayed out because Access was "Not responding") and killed the *msaccess.exe* process. I then had to retype the function by hand (and add in the `.MoveNext` line!) before I could test it again. 

The simple mistake cost me maybe two minutes of my time. **However**, if I was four hours into a flowing code session where I was writing so much code so quickly that I wasn't even stopping long enough to eat, drink, blink, or, you know, *save my code*, then the same simple mistake could have cost me days of time.

*(Wait a minute. Days?! After "only" going four hours without saving?*   
*Yes. Days. I'll write about why that is in a future article.)*

*Image by [Mari Carmen Díaz](https://pixabay.com/users/maricarmennd9-3511650/?utm%5Fsource=link-attribution&utm%5Fmedium=referral&utm%5Fcampaign=image&utm%5Fcontent=1737624) from [Pixabay](https://pixabay.com/?utm%5Fsource=link-attribution&utm%5Fmedium=referral&utm%5Fcampaign=image&utm%5Fcontent=1737624)*