Examples below in C; other languages may vary or have weird alternative syntactic sugars (until) but in the end it will be a variation on one of the following four.


  • for(;;);
  • while(1);
  • void main() {main()}
  • a: goto a;
These last two are not recommended as in C (and a lot of other languages) they are not truly infinite; each function call requires a new entry on the stack, and each usage of goto (in C) "remember"s its previous location in memory. Thus either of the following, if run indefinitely, will eventually run out of memory and crash. If you must use one of these two, go with the first one, because structured programming kicks ass. There are, of course, languages where the behavior in examples 3 and 4 are normal; LISP and Scheme are able to handle and in fact encourage indefinite tail recursion loops, and Assembly and some forms of BASIC expect you to use simple goto jumps. In fact, in Scheme, the recursive infinite loop is the *only* kind.