明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 963|回复: 2

[已解答] 关于局部变量的理解

[复制链接]
发表于 2015-3-2 12:58:31 | 显示全部楼层 |阅读模式
1  (setq i 1)
2  (Phase  i )

(defun Phase ( / i)
(if (= (rem i 3) 1) (setq Circuit_Phase (strcat (itoa i ) "a")))
(if (= (rem i 3) 2) (setq Circuit_Phase (strcat (itoa i ) "b")))
(if (= (rem i 3) 0) (setq Circuit_Phase (strcat (itoa i ) "c")))

(princ Circuit_Phase)
(setq i (1+ i))
)

先给变量赋值(setq i 1) ,然后执行多次 (Phase  i )  应该怎么写变量能让依次(princ Circuit_Phase)结果为1a, 2b,3c
这里搞不懂( / i )    貌似每次都执行是1a
谢谢解答
发表于 2015-3-2 14:14:53 | 显示全部楼层
本帖最后由 Gu_xl 于 2015-3-2 14:16 编辑

全局变量不要和局部变量重名!
1  (setq i 1)
2  (Phase  )

(defun Phase ( )
(if (= (rem i 3) 1) (setq Circuit_Phase (strcat (itoa i ) "a")))
(if (= (rem i 3) 2) (setq Circuit_Phase (strcat (itoa i ) "b")))
(if (= (rem i 3) 0) (setq Circuit_Phase (strcat (itoa i ) "c")))

(princ Circuit_Phase)
(setq i (1+ i))
)
 楼主| 发表于 2015-3-2 17:26:44 | 显示全部楼层
十分感谢,感觉懵懂了
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2025-5-23 11:43 , Processed in 0.152396 second(s), 25 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表