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

Programming in Emacs Lisp

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

11.1 while

The while special form tests whether the value returned by evaluating its first argument is true or false. This is similar to what the Lisp interpreter does with an if; what the interpreter does next, however, is different.

In a while expression, if the value returned by evaluating the first argument is false, the Lisp interpreter skips the rest of the expression (the body of the expression) and does not evaluate it. However, if the value is true, the Lisp interpreter evaluates the body of the expression and then again tests whether the first argument to while is true or false. If the value returned by evaluating the first argument is again true, the Lisp interpreter again evaluates the body of the expression.

The template for a while expression looks like this:

(while true-or-false-test

Looping with while  Repeat so long as test returns true.
11.1.1 A while Loop and a List  A while loop that uses a list.
11.1.2 An Example: print-elements-of-list  Uses while, car, cdr.
11.1.3 A Loop with an Incrementing Counter  A loop with an incrementing counter.
11.1.4 Loop with a Decrementing Counter  A loop with a decrementing counter.

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