While循环
早上好如果达到条件,是否有类似于while循环的东西会中途退出循环?
例如
(setq test 0)
(while (<= test 10)
(setq test (1+ test))
(princ test)
(setq test (1+ test))
(princ test)
(setq test (1+ test))
(princ test)
)
(repeat 10
(......)
)
发生的情况是,每次检查都要将值增加3次,我认为每次检查都必须增加一次值:
(while <test statement> ; if true, do the expressions below, if false - don't evaluate the expressions/stop the loop
<expressions> ; evaluate the expressions, and run the <test statement> again
)
或者检查每个子增量,这令人沮丧:
(setq n 0)
(while (< n 10)
(setq n (1+ n))
(print n)
) 谢谢李,像往常一样,这是一个很好的解决方案,我从来都不知道你可以像那样在while命令中添加“and”
欢迎您,Steven-任何表达式都可以在一段时间内构成测试表达式。 Thanks Lee, as always a great solution, I never knew you could add 'and' to a while command like that
You're welcome Steven - any expression can constitute the test expression for a while loop.
页:
[1]