Here's one way to display the even numbers from a sequence of 10 values in LISP:
(let ((numbers '(1 2 3 4 5 6 7 8 9 10)))
(dolist (num numbers)
(when (evenp num)
(print num))))
This code starts by defining a variable called numbers
and assigning it a list of integers from 1 to 10. Then, it uses the dolist
function to iterate over each element in the list. For each element, it checks if it's even using the evenp
function. If it is, it prints the number to the console using print
.
This code should output the even numbers:
2
4
6
8
10
Asked: 2022-05-06 11:00:00 +0000
Seen: 1 times
Last updated: Feb 10 '23