How to resolve the algorithm Loops/Continue step by step in the Common Lisp programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Loops/Continue step by step in the Common Lisp programming language

Table of Contents

Problem Statement

Show the following output using one loop.

Try to achieve the result by forcing the next iteration within the loop upon a specific condition, if your language allows it.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Loops/Continue step by step in the Common Lisp programming language

Source code in the common programming language

(do ((i 1 (1+ i)))
    ((> i 10))
  (format t "~a~:[, ~;~%~]" i (zerop (mod i 5))))

(do ((i 1 (1+ i)))
    ((> i 10))
  (write i)
  (when (zerop (mod i 5))
    (terpri)
    (go end))
  (write-string ", ")
  end)

(do ((i 1 (1+ i)))
    ((> i 10))
  (write i)
  (if (zerop (mod i 5))
    (terpri)
    (write-string ", ")))


(loop for i from 1 to 10
      do (write i)
      if (zerop (mod i 5))
        do (terpri)
      else
        do (write-string ", "))

(loop for i from 1 to 10 do
  (block continue
    (write i)
    (when (zerop (mod i 5))
      (terpri)
      (return-from continue))
    (write-string ", ")))


  

You may also check:How to resolve the algorithm Zhang-Suen thinning algorithm step by step in the JavaScript programming language
You may also check:How to resolve the algorithm Trigonometric functions step by step in the Jsish programming language
You may also check:How to resolve the algorithm Zhang-Suen thinning algorithm step by step in the BASIC programming language
You may also check:How to resolve the algorithm Sorting algorithms/Merge sort step by step in the Go programming language
You may also check:How to resolve the algorithm Chinese remainder theorem step by step in the Coffeescript programming language