Jump to content

Loops/Continue: Difference between revisions

m (→‎{{header|Oforth}}: Replace rem by mod)
Line 365:
 
===Direct Approach===
<lang ela>open consolemonad imperativeio
loop n | n > 10 = ()
if n > 10 then do
| else = rec write (show n) f `seq` loop (n+1)
return ()
where f | n % 5 == 0 = "\r\n"
| else = ", "do
putStr (show n)
putStr f
loop 1</lang>
loop (n + 1)
where f | n % 5 == 0 = "\r\n"
| else = ", "
 
_ = loop 1 ::: IO</lang>
Function rec creates a cyclic version of a given function, it is defined in imperative module as 'rec f x = f x `seq` rec f' where 'seq' is a sequencing operator.
 
===Using list===
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.