SFTW120-LectureNotes-16

SFTW120-LectureNotes-16 - SFTW120 Programming Science...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
1 SFTW120 Programming Science Lecture Notes 16: Lisp: Iteration Structures © Robert P. Biuk-Aghai SFTW120 - Programming Science 2 Lecture Notes 16 Lisp Iteration Structures Lisp has 4 different iteration structures: dolist – executes its body once for every element in a given list dotimes – executes its body a given number of times do, do* – repeatedly executes its body until an end condition is reached loop – repeatedly executes its body, indefinitely Most useful iteration structures are dolist and dotimes
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 SFTW120 - Programming Science 3 Lecture Notes 16 dolist s For processing all the elements of a list s Format of dolist statement: (dolist ( var list result ) ( statement ) . ..) s var is a variable to hold a list element s list is the list to be processed s result is the result value of dolist (optional, if omitted it is nil ) s statement is a Lisp expression SFTW120 - Programming Science 4 Lecture Notes 16 Example of dolist (dolist (elem ‘(a b c d)) (print elem)) Prints the elements of the list, each on a line by itself, and returns nil : A B C D NIL
Background image of page 2
3 SFTW120 - Programming Science 5 Lecture Notes 16 dotimes s For performing some action a given number of times s Format of dotimes statement: (dotimes ( var count result ) ( statement ) . ..) s var is a variable to hold an integer (initially zero)
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 05/04/2011 for the course SFST 120 taught by Professor Dr.robert during the Spring '11 term at University of Macau.

Page1 / 9

SFTW120-LectureNotes-16 - SFTW120 Programming Science...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online