ForNext
Only Do What Only You Can Do
114. generator
Hyperpolyglot Interpreted Languages: Tcl, Lua, JavaScript, Io より (2012.05.08)
JavaScript
none
Lua
crt = coroutine.create( function (n) while (true) do coroutine.yield(n % 2) n = n + 1 end end ) status, retval = coroutine.resume(crt, 1) if status then print("parity: " .. retval) else print("couldn't resume crt") end _, retval = coroutine.resume(crt) print("parity: " .. retval)
Io
none; although Io has coroutines, yield and resume do not pass values. Also, yield returns control to a scheduler, not the caller.