Dolist Construct in LISP
DoList in Common LISP is a looping statement used to iterate the elements in a list.
(dolist input_list) statements... )
- The input_list contains the list of elements that are iterated.
- The statements are present in the loop.
Example 1: LISP Program to iterate the list of elements from 1 to 5.
List of elements: 1 List of elements: 2 List of elements: 3 List of elements: 4 List of elements: 5
Example 2: LISP Program to find the square of each element by iteration.
Element's value: 1 Square of element: 1 Element's value: 2 Square of element: 4 Element's value: 3 Square of element: 9 Element's value: 4 Square of element: 16 Element's value: 5 Square of element: 25