Run Code
|
API
|
Code Wall
|
Users
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
An awkward iteration
//JavaScript-C24.2.0 (SpiderMonkey) print("Hello, world!") // A function that returns an iterator for a range of integers function rangeIter(first, last) { let nextValue = Math.ceil(first); return { next: function () { if (nextValue > last) throw StopIteration; return nextValue++; } }; } // A awkward iteration using the range iterator let r = rangeIter(1, 5); while (true) { try { print(r.next()); } catch (e) { if (e == StopIteration) break; else throw e; } }
run
|
edit
|
history
|
help
0
Please
log in
to post a comment.
My Code1
Javascript is weird
Javascript Closure
zeroMatrix
replaceMethod
CWG - pages
linq-style in javascript
Alternating Sign Fibonacci
LazyListJS
tt
Please log in to post a comment.