From: Sungwoo, Lim
Subject: [Q] 'if' or 'when' in 'loop'
Date: 
Message-ID: <220320011123322144%sungwoo@cad.strath.ac.uk>
Hello,

I got a problem to code something with 'loop'.
Basically, I am trying to insert following codes into 'loop',
however, it seems difficult to me. 

;------
(if (= (aref arr i) 1)
  (cond ((zerop (aref arr (- i 1)) 1) 
         (count i))
        ((= (aref arr (- i 1)) 1)
         (if (> (- (aref arr1 i) (aref arr1 (- i 1))) 1)
           (count i)
           nil))))
;---------------------

How can I convert the above codes into 'loop'?
I tried to use 'if' and 'when', but it doesn't work.
For example,

(setf my-num (loop for i from 1 to (- ver-num 2)
                   when (= (aref vertices-for-polygon i) 1)
                       when (zerop (aref vertices-for-polygon (- i 1)))
                           count i
     ; error here.->   else (= (aref vertices-for-polygon (- i 1)) 1) 
                           when (> (- (aref index-number i) 
                                   (aref index-number (- i 1))) 1)
                               count i))

Thanks,

Sungwoo

From: Sungwoo, Lim
Subject: Re: [Q] 'if' or 'when' in 'loop'
Date: 
Message-ID: <220320011156402225%sungwoo@cad.strath.ac.uk>
Sorry, I just solve the problem as

(setf my-num (loop for i from 1 to (- ver-num 2)
                    when (= (aref vertices-for-polygon i) 1)
                        when (zerop (aref vertices-for-polygon (- i 1)))
                            count i
                        else  
                            when (> (- (aref index-number i) 
                                    (aref index-number (- i 1))) 1)
                                count i))
 
Thanks,
 
Sungwoo
From: Sungwoo, Lim
Subject: Re: [Q] 'if' or 'when' in 'loop'
Date: 
Message-ID: <220320011332087928%sungwoo@cad.strath.ac.uk>
In article <················@naggum.net>, Erik Naggum <····@naggum.net>
wrote:

> * "Sungwoo, Lim" <·······@cad.strath.ac.uk>
> > I tried to use 'if' and 'when', but it doesn't work.
> 
>   Stylistically, when should not take an else branch.
> 
> #:Erik

Thanks, =)

Sungwoo