Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I remember once reading some research where a body of C code had been analysed, and the findings were that the vast majority of for loops could be categorised into about five categories, corresponding to the functional equivalents of map, filter, fold, etc.

I can't seem to find this paper/article anymore. Can anyone point me to it?

share|improve this question
I found something similar on stack overflow: Maybe there you will find some info about this article. – Thaven Jan 8 '13 at 10:25
homomorphisms, catamorphisms and anamorphisms etc. might be worth a google, for loops that aren't on lists – jk. Jan 11 '13 at 15:13

This isn't an exact match for what you were requesting, but I think it gets pretty close to the root of your question.

This site's page on Loops discusses a number of looping patterns.

  • counting
  • filtered-count
  • accumulate
  • filtered-accumulate
  • search
  • extreme
  • extreme-index
  • filter
  • map
  • shuffle
  • merge
  • fossilized
  • missed-condition

They also have a page on Recursion that covers many of the same patterns in a recursive manner.

share|improve this answer
...I was hoping "extreme" loops would be more, well, extreme... ;) – Izkata Jan 8 '13 at 20:43

I think I've heard it too. Somewhere in the SICP-videos or the book i think I heard that most (if not all) programs/algorithms can be expressed using streams and filters. Streams starts at lecture 6A.

As for all loops (for, while, do-while and so on) they all are implemented with label, compare and conditional jump so they are just syntactic sugar to make it easier to read and understand.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.