你可以这样写:
- (defun C:TEST ()
- (setq door nil;_T is open, nil is closed
- window nil ;_T is open, nil is closed
- driving T;_T is driving nil is not
- )
- (if door
- (if window
- (if driving
- (princ "\nStop it right now, you #$@*")
- (princ "\nPut your belt! Don't forget the door!!")
- )
- (if driving
- (princ "\nSami, one day you'll die!")
- (princ "\nClose the door and start your engine!!!")
- )
- )
- (if window
- (if driving
- (princ "\nYou know, this car has air conditioning...")
- (princ "\nFinaly, we can go! Just close the window, please")
- )
- (if driving
- (princ "\nYour door and window are closed, drive saftly!")
- (princ "\nYour door and window are closed, you might start driving")
- )
- )
- )
- (princ)
- )
但每增加一个选项,代码的大小就会翻倍。
这可能是另一种选择:
- (defun C:TEST ()
- ;driving 1
- ;open door 2
- ;open window 4
- (if
- (setq i (getint "\nEnter a number: "))
- (if (<= 0 i 7)
- (princ
- (strcat "\nYour car is "
- (if (= 1 (logand i 1)) " " "not ")
- "moving. The door is "
- (if (= 2 (logand i 2)) "open " "closed ")
- "and the window is "
- (if (= 4 (logand i 4)) "open!" "closed!")
- )
- )
- )
- )
- (princ)
- )
谢谢
谢伊 |