> why code with loop doesn't work?
While I don't know the exact reason too, I think you need separate thread which handle the readline like this [https://github.com/mashingan/nim-etc/blob/master/cond_loop.nim#L58-L67](https://github.com/mashingan/nim-etc/blob/master/cond_loop.nim#L58-L67)