最初由 fundoll 发布
if语句可不可以嵌套(我试过好象不行)
该怎么办?
可以,看我这段

- (defun tt_t1_psel ()
- (setq xh0 xh)
- (princ "\n拾取一个样板文本:")
- (setq txt (entsel))
- (if txt
- (progn
- (setq txt (entget (car txt)))
- (if (/= (cdr (assoc 0 txt)) "TEXT")
- (tt_t1_psel)
- (progn
- (setq str0 (cdr (assoc 1 txt))
- str1 (tt_substr str0 tt:fg t t)
- )
- (if (or (= str1 "") (= str0 "Other"))
- (progn
- (alert "所选实体没有型号")
- (mode_tile "15" 2)
- )
- (if (and (= (tt_xh str1) "Other") (/= str0 "Other"))
- (progn
- (if (not (new_dialog "t1_alert" dcl_id)) (exit))
- (action_tile "accept" "(done_dialog 1)")
- (action_tile "cancel" "(done_dialog 0)")
- (if (= (start_dialog) 0)
- (progn
- (setq xh xh0)
- (set_tile "15" xh)
- (mode_tile "15" 2)
- )
- (progn
- (setq xh str1)
- (set_tile "15" xh)
- )
- )
- )
- )
- )
- )
- )
- )
- (tt_t1_psel) ;子函数自身嵌套——递归
- )
- )
if一般不进行多层嵌套,需要多项判断时一般用cond,但有时用if嵌套可能使程序更容易理解些。 |