By next I mean next as found in ruby/perl/python/etc


for i in 0..5
   if i < 2 then
   puts "Value of local variable is #{i}"

3 Answers 3


There is no such facility for loops. Considering next in Ruby is the idiom to avoid a nested if, you can easily work around this by using this advice the other way around.

(dotimes (i 6)
  (unless (< i 2)
    (message "Value of local variable is %d" i)))

An even uglier workaround is using the throw/catch facility (which is designed for control flow, not exception handling):

(dotimes (i 6)
  (catch 'next
    (when (< i 2)
      (throw 'next t))
    (message "Value of local variable is %d" i)))

I'd recommend rethinking the problem so that you don't need next at all. Or use a more powerful looping construct, such as cl-loop.


The next statement is just a jump to the end of the loop. Emacs Lisp doesn't have one but it does have "goto":

(dotimes (i 5)
   (when (< i 2)
     (go next))
   (message "Value of i is %d." i)

(Here next is just an arbitrary label, specifying a target for the jump.)

I don't actually recommend this style. Prbably rephrasing your loop to avoid next is better.


Using cl-loop:

(cl-loop for i from 0 to 5
         unless (< i 2)
         do (message "Value of local variable is %d" i))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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