1
0
mirror of https://github.com/janet-lang/janet synced 2025-10-18 01:07:40 +00:00

Add early returns via break.

Inside a while loop, the argument to
break does nothing as while loops always
return nil.
This commit is contained in:
Calvin Rose
2019-03-09 22:01:10 -05:00
parent 9a080197e7
commit 8ba1121161
2 changed files with 35 additions and 9 deletions

View File

@@ -74,4 +74,10 @@
(assert (= nil ((fn [] (break) 4))) "break 2")
# Break with value
# Shouldn't error out
(assert-no-error "break 3" (for i 0 10 (if (> i 8) (break i))))
(assert-no-error "break 4" ((fn [i] (if (> i 8) (break i))) 100))
(end-suite)