Jump to content

How to write a Condition where either one is true


gsc

Recommended Posts

Hi,

I have a list (tmp_list1) that may contains at least 1 or more of the following strings:

  • 00-Structure Safety Zone-temp
  • 01-Create IAC-Safety Zones-temp
  • 02-Create Scour Protections-temp
  • 03-Create Archaeological Areas-temp
  • 04-Create Maintenance Zones-temp
  • 05-Create Seabed Steep Slope Areas-temp
  • 06-Create Rock Steep Slope Areas-temp
  • 07-Create Sediment Thickness-temp

 

With a foreach function I want to compare per string, 1 by 1 whether the string equals 1 of the 3 expressions in the condition
However, for the 2nd and 3rd expressions, the value of the string must equal 1 of those (3 or 4) possibilities.
I thought I could achieve this with the OR function, but this apparently does not work.


What am I doing wrong here?


 

(foreach itm tmp_lst1
	(cond
		((equal (car itm) "00-Structure Safety Zone-temp")
			(print (strcat "this is " (car itm)))
		)
		((or
				(equal (car itm) "01-Create IAC-Safety Zones-temp")
				(equal (car itm) "02-Create Scour Protections-temp")
				(equal (car itm) "03-Create Archaeological Areas-temp")
				(equal (car itm) "04-Create Maintenance Zones-temp")
			)
			(print (strcat "this is " (car itm)))
		)
		((or 
				(equal (car itm) "05-Create Seabed Steep Slope Areas-temp")
				(equal (car itm) "06-Create Rock Steep Slope Areas-temp")
				(equal (car itm) "07-Create Sediment Thickness-temp")
			)
			(print (strcat "this is " (car itm)))
		)
	) ;end cond
) ;end foreach

 

Link to comment
Share on other sites

maybe :

(defun t1 ( / tmp-lst )
  (setq tmp_lst1 '("00-Structure Safety Zone-temp" "01-Create IAC-Safety Zones-temp" "02-Create Scour Protections-temp"
                   "03-Create Archaeological Areas-temp" "04-Create Maintenance Zones-temp" "05-Create Seabed Steep Slope Areas-temp"
                   "06-Create Rock Steep Slope Areas-temp" "07-Create Sediment Thickness-temp"))
  (foreach itm tmp_lst1
    (cond
      ((equal itm  "00-Structure Safety Zone-temp") (print (strcat "this is " itm)))
      ((member itm '("01-Create IAC-Safety Zones-temp" "02-Create Scour Protections-temp" "03-Create Archaeological Areas-temp" "04-Create Maintenance Zones-temp"))
       (print (strcat "this is " itm)))
      ((member itm '("05-Create Seabed Steep Slope Areas-temp" "06-Create Rock Steep Slope Areas-temp" "07-Create Sediment Thickness-temp"))
       (print (strcat "this is " itm)))
    )
  )
)

 

 

You keep comparing (car itm) for every member in list...

🐉

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...