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

Published on 12 May 2024 09:40 PM

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

Table of Contents

Problem Statement

“For”   loops are used to make some block of code be iterated a number of times, setting a variable or parameter to a monotonically increasing integer value for each execution of the block of code. Common extensions of this allow other counting patterns or iterating over abstract structures other than the integers.

Show how two loops may be nested within each other, with the number of iterations performed by the inner for loop being controlled by the outer for loop. Specifically print out the following pattern by using one for loop nested in another:

Let's start with the solution:

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

Source code in the common programming language

(loop for i from 1 upto 5 do
  (loop for j from 1 upto i do
    (write-char #\*))
  (terpri))


(dotimes (i 5)
  (dotimes (j (+ i 1))
    (write-char #\*))
  (terpri))


(do ((i 1 (+ i 1)))
    ((> i 5))
  (do ((j 1 (+ j 1)))
      ((> j i))
    (write-char #\*))
  (terpri))


(use-package :iterate)
(iter
  (for i from 1 to 5)
    (iter
      (for j from 1 to i)
      (princ #\*))
    (terpri))


  

You may also check:How to resolve the algorithm Koch curve step by step in the Maxima programming language
You may also check:How to resolve the algorithm Associative array/Creation step by step in the Delphi programming language
You may also check:How to resolve the algorithm Brownian tree step by step in the Locomotive Basic programming language
You may also check:How to resolve the algorithm Morse code step by step in the Mathematica/Wolfram Language programming language
You may also check:How to resolve the algorithm System time step by step in the HolyC programming language