LOOP有自己的IF语句,可以控制子句的执行方式:
(loop repeat 1000 for x = (random 100) if (evenp x) collect x into evens else collect x into odds finally (return (values evens odds)))
在IF主体中组合多个子句需要特殊的语法:
(loop repeat 1000 for x = (random 100) if (evenp x) collect x into evens and do (format t "~a is even!~%" x) else collect x into odds and count t into n-odds finally (return (values evens odds n-odds)))