Just about every answer here mentions some situation where an infinite loop was/is actually intentional and nothing to be embarrassed about. I will step up and offer myself as a subject of ridicule so that others may learn from (or laugh at) my mistake:
Basically, I had code like this that ran on a Threading.Timer:
private Queue<Snapshot> snapshots;
// code code code
public void SaveSnapshots() {
while (snapshots.Count > 0) {
Snapshot snapshot = snapshots.Dequeue();
snapshot.SaveToFile();
}
}
At some point it was decided that we should hold (i.e., not save) Snapshots until a certain condition was reached, so the above code became:
private Queue<Snapshot> snapshots;
// code code code
public void SaveSnapshots() {
while (snapshots.Count > 0) {
Snapshot snapshot = snapshots.Dequeue();
if (snapshot.AnalyticsComplete) {
snapshot.SaveToFile();
} else {
snapshots.Enqueue(snapshot);
}
}
}
Testing this quickly in the development environment (with only a fraction the number of simultaneous threads as production) didn't uncover any hiccups. It went on to production. Then, before long, it became apparent that something was badly slowing down our processing.
To my credit (?), I figured out the problem and deployed the fix within about ten minutes.
Also, as if it even needs to be said: our company does not have a testing department.