[Haskell-cafe] loop problem

Jochem Berndsen jochem at functor.nl
Sat May 10 15:54:50 UTC 2014


On 05/10/2014 05:53 PM, Roelof Wobben wrote:
> Thanks , it's working now like this :
>
> loop :: Int -> IO ()
> loop n = do
>     if n <= 100
>     then do
>         putStrLn (show n );
>         putChar ' ';
>         putStrLn (show (n * n )) ;
>         loop (n + 1);
>     else
>        return () ;
>
> main :: IO ()
> main = loop 1
>
> But the outcome looks like this:
>
> 1
>    1
> 2
>    4
>
> Can I somehow make it like this
>
> 1   1
> 2    4
> 3    9
>
> Roelof
>
Take a look at the `putStr' function. It omits the newline character 
that putStrLn writes at the end of the string.

Jochem

-- 
Jochem Berndsen | jochem at functor.nl

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20140510/8dde76d4/attachment.html>


More information about the Haskell-Cafe mailing list