Hi Jess users,
I have the following function:
(deffunction similarity-score (?base ?other)
(bind ?score 0)
(bind ?totalDistance 0)
(bind ?counter 0)
(foreach ?x ?base
(bind ?counter (+ ?counter 1))
(printout t "counter is:" ?counter)
(bind ?partialDistance 0)
(printout t "partialDist is:" ?partialDistance)
(foreach ?y ?other
(bind ?partialDistance (+ ?partialDistance 1))
(printout t "foreach partialDist is:" ?partialDistance)
(if (eq ?x ?y) then
(bind ?score (+ ?score 1))
(printout t "score is:" ?score)
(return)
)
)
(bind ?totalDistance (/ ?counter ?partialDistance))
)
(return (- (/ ?score (length$ ?base)) (* (- 1 (/ (length$ ?base)
?totalDistance)) 0.1) ))
)
As you can see, the above function has a nested foreach loop, which upon
finding equal values in both list should skip to the next iteration of the
outer loop. In java, instead of (return) one would normally put a break
statement. As far as the documentation of the (foreach) construct reads, it
says: "The return function can be used to break the iteration". However,
what I am finding is that the (return) function terminates the outer loop
too - unless I seriously messed up the code - but this is the result of my
observation of the (printout t) function. Moreover, when I remove the
(return) function, the function iterates over the outer and inner loops
just fine.
Any advice on how can I break the inner's loop iteration? I know I can use
a variable to flag that the match has been found and add it to the if
statement, but I am hoping that there is an equivalent of break in Jess.
Cheers,
Pete