title: How to exit a loop in lisp once the function is performed?
body: <p>I am very beginner in LISP and hope that you can solve my confusion for me. My code is as follow:</p>
  
  <pre><code>(defun retrieve (element closed)
              (if (= (length closed) 0)
               (setf closedlist '(a))
                (dolist (count closed)
                (when (equal element (car count))
                 (progn (check (childvalue (symbol-value count)) count) 
                 (return)));;;endif
                );;;endouterloop
              )
             )
  </code></pre>
  
  <p>This is the first function, where it will take in an object called "element", and a list called "closed". The next function is as below:</p>
  
  <pre><code>(defun check (child close)
             (setf tempvalue child)
             (dotimes (count (length tempvalue));;;1st loop
               (setf front (car tempvalue))
               (setf templist close)
               (dotimes (count1 (length close));;;2nd loop
                 (if (= (length close) 1) 
                  (if (string= front (car templist)) 
                      ((remove (nth count) child) (return));;;true
                      (setf templist (car templist));;;else
                   )
                   (if (string= front (car templist)) 
                      (setf child (remove (nth count child) child))
                      (setf templist (cdr templist));;;else
                     )
                   )
                 );;;2nd loop
               (setf tempvalue (cdr tempvalue))
               );;;1stloop
             (format t "child ~S~%" child)
             )
  </code></pre>
  
  <p>My question is, from the 1st function, when I am inside the first function and if the condition is met, I will call the second function (check). However, after I call the 2nd function (check) from the 1st function (retrieve) and successfully performed the operations, I want to exit the dotimes loop from the 1st function but I can't do it. </p>
  
  <p>If I try to add (return) to it, the program will just exit the loop, without performing other things inside the statement. In this case, (check (childvalue (symbol-value temp)) (nth count closed)). </p>
  
  <p>Could anybody provide any suggestion on how to exit the loop after calling the secondary function? Thanks.</p>