title: Returning a value from a loop
body: <p>Is there anyway i can return a value from a loop since the recursion has to be at the tail </p>
  
  <pre><code>(ns for)
  
      (defn abc [y]
      (loop [x 10]
        (when (&gt; x 2)
          (if (= 2 3) (do (println "test") (recur (- x 2)))
          (do (let [x (+ 1 x)
                    y 2] (println y) (recur (- x 2))))))))
  
      (abc 1)
  </code></pre>
  
  <p>is there anyway i can return a value for the function by taking y as a parameter and updating a new value of y. However, the recur part has to be at the last line of the code hence i am unable to put y as the last line of the code. </p>
  
  <p>Example </p>
  
  <pre><code>(ns for)
  
      (defn abc [y]
      (loop [x 10]
        (when (&gt; x 2)
          (if (= 2 3) (do (println "test") (recur (- x 2)))
          (do (let [x (+ 1 x)
                    y 2] (println y) (recur (- x 2)))))))
      y)
  
      (abc 1)
  </code></pre>
  
  <p>This would give me an error since recur has to be the last line of code. I have looked at similar questions and it says to put the return value at the end of the if loop which i tried but failed which gives me an exception thatthe recursion can only happen at the tail  </p>