乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 84|回复: 6

[编程交流] While循环

[复制链接]

48

主题

657

帖子

33

银币

限制会员

铜币
-1
发表于 2022-7-5 16:23:30 | 显示全部楼层 |阅读模式
早上好
 
 
如果达到条件,是否有类似于while循环的东西会中途退出循环?
 
 
例如
  1. (setq test 0)
  2. (while (<= test 10)
  3.    (setq test (1+ test))
  4.    (princ test)
  5.    (setq test (1+ test))
  6.    (princ test)
  7.    (setq test (1+ test))
  8.    (princ test)
  9. )
回复

使用道具 举报

63

主题

6297

帖子

6283

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
358
发表于 2022-7-5 16:34:14 | 显示全部楼层
  1. (repeat 10
  2.            (......)
  3.          )

 
发生的情况是,每次检查都要将值增加3次,我认为每次检查都必须增加一次值:
 
  1. (while <test statement> [color="green"]; if true, do the expressions below, if false - don't evaluate the expressions/stop the loop[/color]
  2. <expressions> [color="green"]; evaluate the expressions, and run the <test statement> again[/color]
  3. )

 
或者检查每个子增量,这令人沮丧:
 
  1. (setq n 0)
  2. (while (< n 10)
  3. (setq n (1+ n))
  4. (print n)
  5. )
回复

使用道具 举报

66

主题

1552

帖子

1514

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
325
发表于 2022-7-5 16:46:42 | 显示全部楼层
谢谢李,像往常一样,这是一个很好的解决方案,我从来都不知道你可以像那样在while命令中添加“and”
回复

使用道具 举报

48

主题

657

帖子

33

银币

限制会员

铜币
-1
发表于 2022-7-5 16:56:47 | 显示全部楼层
 
欢迎您,Steven-任何表达式都可以在一段时间内构成测试表达式。
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-5 17:08:32 | 显示全部楼层
回复

使用道具 举报

48

主题

657

帖子

33

银币

限制会员

铜币
-1
发表于 2022-7-5 17:21:04 | 显示全部楼层
Thanks Lee, as always a great solution, I never knew you could add 'and' to a while command like that
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-5 17:29:08 | 显示全部楼层
 
You're welcome Steven - any expression can constitute the test expression for a while loop.
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-14 21:09 , Processed in 0.359378 second(s), 66 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表