label.zy 741 B

1234567891011121314151617181920212223
  1. // break/continue in for loop with label
  2. (def isum 0)
  3. (def jsum 0)
  4. (for outerLoop: [(def i 1) (< i 5) (++ i)]
  5. //(set isum (+ isum i))
  6. (set isum (+ isum i))
  7. (for innerLoop: [(def j 1) (< j 5) (++ j)]
  8. //(printf "i = %v j = %v\n" i j)
  9. (set jsum (+ jsum j))
  10. //(printf " -- after inner increment, jsum is %v\n" jsum)
  11. (cond (> j 2) (continue outerLoop:)
  12. (and (> i 2) (> j 3)) (break outerLoop:)
  13. null)
  14. //(printf "advancing jsum %v -> %v\n" jsum (+ jsum 1000))
  15. (set jsum (+ jsum 1000))// check continue works
  16. )
  17. )
  18. //(printf "isum is %d\n" isum)
  19. //(printf "jsum is %d\n" jsum)
  20. (assert (== isum 10))
  21. (assert (== jsum 8024))