G'day everyone
I'm not sure how I'd handle this, as I'm just thinking about it now, but how would one implement a (for) that had two indices rather than the usual one?
For example (pseudopseudocode):
for i = 1 to 10 with j=20 to 2 step -2 do
println i,j
next
The usual thing is to have the for j inside the for i and to get about 100 results. I was thinking more of getting as many results as it takes for either i or j to terminate. That is, if i gets to 10 before j gets to 2 then terminate or vice versa.
I may come up with something soon, but if anyone wants to offer a solution, I'd be very interested.
Kind regards,
Bruce.
need an enhanced (for)
Code: Select all
(setq j 20)
(for (i 1 10 1 (= j 0))
(println (string "i=" i "j=" j))
(setq j (- j 2))
)
Hans-Peter
Wow, would never of thought of that approach. Thanks!!HPW wrote:Code: Select all
(setq j 20) (for (i 1 10 1 (= j 0)) (println (string "i=" i "j=" j)) (setq j (- j 2)) )
Kind regards,
Bruce.
However, what I ended up doing was:axtens wrote:HPW wrote:Code: Select all
(setq j 20) (for (i 1 10 1 (= j 0)) (println (string "i=" i "j=" j)) (setq j (- j 2)) )
Code: Select all
(setq i ?TestRange1Low)
(setq j ?TestRange2Low)
(while (and (!= i ?TestRange1High) (!= j ?TestRange2High))
(begin
(inc i ?TestIncr1)
(inc j ?TestIncr2)
)
)
Code: Select all
(co-for (i 1 10 1) (j 20 2 -2) (begin ... ) )