Hi Peter, I just came across this thread and it's just what I need right now. I've been searching in vain for a code sample for a loop construct that will do what I need. LISP is a new language to me and I'm finding that it's difficult to make a loop do what I need. It doesn't help that I can't understand a lot of the examples put out there on loops. At this point in my LISP education I need a more robust example. Anyway on to my question.
Background:
I am writing a utility to automatically increment the rev letter or number of legacy title blocks that are still used at our company.
The section of code:
I am building this routine a section at a time. The section I am working on involves a loop that takes the current rev (if it's a letter) and increments it by 1.
Having found no code samples I can understand to use as a template, my idea was to set up a list of the possible values. In our case that would be A-Z and AA-ZZ. I then loop through this list comparing the current rev letter value. As I loop I am counting. Once I have a match I capture the count and add 1 which is then used to get the nth letter of my list as the new letter rev. The code, which follows, is just the initial matching section and it does work. However, the failure is that once I have the match I am setting the condition that should end the while loop but it appears that the while condition is not evaluated. I am sure it's because of the structure of my loop but am at a loss as to how to correct it. I'm betting the foreach loop nested inside the while is just going to keep running. I tried to find a way to break out of the foreach loop but can't find anything that works in LISP. Sorry for the juvenile effort but I have to start somewhere.
Variables used:
arrLetters (the list of letters to compare to)
strLetter (the current rev level)
letter (the current member of arrLetters)
haveMatch (my trigger to supposedly exit the loop)
cntLetter (the counter to actually increment the rev letter)
lstLetter (the last count at the time of match)
I also have some alerts in there to make sure things are happening the way I hoped these will be removed.
Code:(while (/= 1 haveMatch) (foreach letter arrLetters ;; Just making sure my count and letters are changing correctly TBR (alert (strcat (itoa cntLetter) " Letter is " letter)) (if (equal letter strLetter) (progn ;; Verify that I actually find a match TBR (alert "We have a match!") (setq lstLetter letter) (setq haveMatch 1) (setq cntMatch cntLetter) (setq cntLetter (1+ cntLetter)) );end progn (setq cntLetter (1+ cntLetter)) );end if );end foreach );end while