I'm having trouble debugging a nested if statement. Can anyone tell what is wrong. I'm sure it's a logic error on my part. I've labelled the area that won't work. Thanks for any help! (if (= op1 'T) (if (= cb1 'T) (alert "Standard Outlet - 1/2 Hot") (alert "Standard Outlet") ) (if (= op2 'T) ;;-------------------- begin of failing statement (if (cb2 'T) (if (cb3 'T) (alert "GFCI - Under Counter - WP") (alert "GFCI - Under Counter") ) (if (cb3 'T) (alert "GFCI - WP") (alert "GFCI") ) ) ;;-------------------- end of failing statement (if (= op3 'T) (if (= cb4 'T) (alert "AFCI - 1/2 Hot") (alert "AFCI") ) ) ) )
I think you've got 3 branches under your opening if instead of the 2 allowed. Try commenting out ifs , from the innermost outward, to check. IMHO a cond structure is usually simpler to understand and debug than heavily nested ifs, when multiple conditions are involved.
(if op1 (progn ;do_what_ever (if what_ever (progn ;do_this_or_that ) ) ) ) -- AUTODESK Authorized Developer www.Cadentity.com MASi
Ya, And you forgot your "=" signs: (if (=cb2 'T) (if (=cb3 'T) (alert "GFCI - Under Counter - WP") (alert "GFCI - Under Counter") ) (if (=cb3 'T)
Haha, that was it, the = was missing. Thanks BillZ I am still a novice, and a cond structure is probably the better way to do this, but until Tom Smith mentioned that I didn't know to look for that. So thanks everyone for your help! kemp
Could do with (progn.. ;; (if (= cb2 'T) (progn (if (= cb3 'T) (alert "GFCI - Under Counter - WP") (alert "GFCI - Under Counter") ); eif (if (/= cb3 'T) (alert "GFCI - WP") (alert "GFCI") ); eif ); epr ); eif Bob Shaw
or simply (if cb2 (do this) (else do this) ) -- Ken Alexander Acad2004 Windows2000 Prof. "We can't solve problems by using the same kind of thinking we used when we created them." --Albert Einstein
: Kemp, Nobody above used the AND Boolean... (if (and (= op1 'T) (= cb1 'T)) (progn (alert "Standard Outlet - 1/2 Hot") (princ "\n1/2 Hot") );progn (progn (alert "Standard Outlet") (princ "\nStandard") );progn );if When more than two actions are needed in a IF, you will need to use PROGN... You may also try to do this in a COND. (cond ( (and (= a 1)(= b 2)) ([evaluate]) ) ( (= c 3) ([evaluate]) ) ( (or (= d 4)(/= e 5)) ([evaluate]) ) (a ([evaluate]) ) );cond Scot-65