Author Topic: if statement question  (Read 2342 times)

0 Members and 1 Guest are viewing this topic.

andrew_nao

  • Guest
if statement question
« on: August 05, 2014, 03:12:30 PM »
whats the best way to approach if statements.

basically im wanting match var 1 to either var 2, 3 or 4 and if var 1 is does not match var 2, 3 or 4 then do my thing.

thnks

kpblc

  • Bull Frog
  • Posts: 396
Re: if statement question
« Reply #1 on: August 05, 2014, 03:26:33 PM »
I didn't test the speed. For example:
Code: [Select]
(defun test (/ var1 var2 var3 var4)
  (setq var1 12
var2 13
var3 15
var3 123
  )

  ;; variant 1
  (if (not (member var1 (list var2 var3 var4)))
      ;; do what you want
  )

  ;; variant 2
  (if (not (apply (function or)
  (mapcar
    (function
      (LAMBDA (x)
(equal var1 x 1e-3)
      )
    )
    (list var2 var3 var4)
  )
   )
      )
      ;; do what you want
  )
)
Sorry for my English.

ronjonp

  • Needs a day job
  • Posts: 7529
Re: if statement question
« Reply #2 on: August 05, 2014, 03:36:12 PM »
Couple more:
Code: [Select]
  (if (vl-some '(lambda (x) (equal var1 x)) (list var2 var3 var4))
      ;; Exit
      ;; do what you want
  )
  (if (vl-position var1 (list var2 var3 var4))
      ;; Exit
      ;; do what you want
  )

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: if statement question
« Reply #3 on: August 05, 2014, 05:21:16 PM »
Another:
Code: [Select]
(if (or (equal var1 var2)
        (equal var1 var3)
        (equal var1 var4)
    )
    ;; do what you want
)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: if statement question
« Reply #4 on: August 06, 2014, 07:42:11 AM »
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

andrew_nao

  • Guest
Re: if statement question
« Reply #5 on: August 06, 2014, 03:01:25 PM »
For Andrew
http://www.theswamp.org/index.php?topic=13046.msg158557#msg158557

excellent post CAB,
thanks for this

and thank you everyone for your help

snownut2

  • Swamp Rat
  • Posts: 971
  • Bricscad 22 Ultimate
Re: if statement question
« Reply #6 on: August 08, 2014, 08:32:59 AM »

Code: [Select]
  (if (vl-position var1 (list var2 var3 var4))
      ;; Exit
      ;; do what you want
  )

Good one ronjonp......

ronjonp

  • Needs a day job
  • Posts: 7529
Re: if statement question
« Reply #7 on: August 08, 2014, 08:42:22 AM »

Code: [Select]
  (if (vl-position var1 (list var2 var3 var4))
      ;; Exit
      ;; do what you want
  )

Good one ronjonp......
:)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC