How to create an infinite loop

Obvious in retrospect, but took me a minute to catch on to what’s going on here:

public void DoStuff(byte maximum)
    for(byte i = 1; i <= maximum; i++)
      // whatever

This works like a trooper until someone passes in a byte.MaxValue in a unit test and i becomes 0 after reaching maximum and getting incremented again.

  • Disclaimer: The opinions expressed on this site are my own personal opinions and do not in any way represent my employer's view.
  • Twitter Updates

    Error: Twitter did not respond. Please wait a few minutes and refresh this page.

  • Archives

  • Advertisements