How to resolve the algorithm Loops/While step by step in the Clojure programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Loops/While step by step in the Clojure programming language

Table of Contents

Problem Statement

Start an integer value at   1024. Loop while it is greater than zero. Print the value (with a newline) and divide it by two each time through the loop.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Loops/While step by step in the Clojure programming language

Source code in the clojure programming language

(def i (ref 1024))

(while (> @i 0)
  (println @i)
  (dosync (ref-set i (quot @i 2))))


(loop [i 1024]
  (when (pos? i)
    (println i)
    (recur (quot i 2))))


(doseq [i (take-while pos? (iterate #(quot % 2) 1024))]
  (println i))


  

You may also check:How to resolve the algorithm Sierpinski carpet step by step in the Python programming language
You may also check:How to resolve the algorithm Palindrome detection step by step in the Ruby programming language
You may also check:How to resolve the algorithm Quine step by step in the ooRexx programming language
You may also check:How to resolve the algorithm Loops/Foreach step by step in the Lingo programming language
You may also check:How to resolve the algorithm Text processing/2 step by step in the C# programming language