Emacs Lisp: Loop, Iteration

By Xah Lee. Date: .

Most basic loop in elisp is with while.

(while test body)

, where body is one or more lisp expressions.

(setq x 0)

(while (< x 4)
  (print (format "number is %d" x))
  (setq x (1+ x)))
;; inserts Unicode chars 32 to 126
(let ((x 32))
  (while (< x 127)
    (insert-char x)
    (setq x (+ x 1))))

Usually it's better to use dolist or dotimes.

[see Emacs Lisp: Sequence Iteration]

(info "(elisp) Iteration")

Break/Exit a Loop

Emacs Lisp: throw, catch, exit function

Lisp Basics

Lisp Basics


Lisp Data Structure


Lisp Symbol

Lisp Misc

Working with Elisp