www.delorie.com/gnu/docs/emacs-lisp-intro/emacs-lisp-intro_154.html   search  
Buy the book!

Programming in Emacs Lisp

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

11. Loops and Recursion

Emacs Lisp has two primary ways to cause an expression, or a series of expressions, to be evaluated repeatedly: one uses a while loop, and the other uses recursion.

Repetition can be very valuable. For example, to move forward four sentences, you need only write a program that will move forward one sentence and then repeat the process four times. Since a computer does not get bored or tired, such repetitive action does not have the deleterious effects that excessive or the wrong kinds of repetition can have on humans.

People mostly write Emacs Lisp functions using while loops and their kin; but you can use recursion, which provides a very powerful way to think about and then to solve problems(8).

11.1 while  Causing a stretch of code to repeat.
11.2 Save your time: dolist and dotimes  
11.3 Recursion  Causing a function to call itself.
11.4 Looping Exercise  

  webmaster   donations   bookstore     delorie software   privacy  
  Copyright 2003   by The Free Software Foundation     Updated Jun 2003