lisp

lisp中,do循环形象如下:

1
2
3
(do (variable-definition*)
(end-test-form result-form*)
statement*);

其中,(variable-definition*)是一些行日(var init next)的赋值结构。在do开始时,var会被赋值为init。并且在一次循环结束后,var会被赋值为next所表示的内容。
形如:

1
2
3
4
5
(do ((n 0 (+ 1 n))
(cur 0 next)
(next 1 (+ cur next)))
((= 10 n) (format t "|end ~d" cur))
(format t "~d|" cur));

输出:

1
0|1|1|2|3|5|8|13|21|34||end 55

类似于python中的:

1
2
3
4
5
6
cur = 0
next = 1
for i in range(10):
print("%d|" % cur)
cur, next = next, cur + next
print("|end %d" % cur)