Answers for "for loop in scheme"

0

for loop in scheme

;This program will use a for loop to add hello n times to an empty list 
(define for_loop
  (lambda (n)
    (cond
      ((zero? n) '()) ;Base case of recursion
      (else
       (cons 'hello (for_loop (- n 1))) ;Recursive case of recursion
       )
      )
    )
  )
(for_loop 9)
Posted by: Guest on February-10-2022

Browse Popular Code Answers by Language