Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8678607
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:45:57+00:00 2026-06-12T20:45:57+00:00

I am trying to make a continues loop that contains multiple when’s. What I

  • 0

I am trying to make a continues loop that contains multiple when’s. What I currently have is this:

(defn test [n]
(loop [x n]
    (when (> x 1)
        (println x))

    (when (even? x)
        (recur (- x 1))
        (println x))
    (when (odd? x)
        (recur (+ x 2))
        (println x))
)

)

Is there a possible way to do this in clojure?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T20:45:59+00:00Added an answer on June 12, 2026 at 8:45 pm

    Your code is not correct. It will go into infinite loop because a number is either even or odd, so on each iteration recur will always be called. Also, it is not obvious what exactly you want to do; if you explain your problem, it will be possible to give more definitive answer.

    You have to define an exit condition first – what do you want this function to return? Then you have to structure your loop in such a way that it will not call recur when exit condition is met. In this case the function will eventually return something.

    It is also highly possible that you can do what you want without even resorting to low-level primitives like loop and recur, using standard functions like map, filter and reduce (or for macro).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to make this jQuery filter that uses .find case-insensitive. For example, when the
I'm trying to make a loop that will recurse through an array of bytes
I'm trying to make a multidimensional array that should print out like this (without
Am trying to make while loop in my C code like this: main() {
I'm trying make an entity with doctrine that has three associations with other entities
Trying to make a simple number clicker control for BlackBerry 6/7, like this: At
I'm new to android development and I'm trying to make an android app that
I'm trying to make sense of a situation I have using entity framework on
Well I have been trying this problem for over 10 hours and have no
I have an application and I'm trying to make sure it's running in a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.