loopsnim-lang

Nim infinite loop


Hi I want an infinite loop in nim. Not a function that inifnitely sleeps, it has to be a loop.

Tried writing this

while true:
  ;

But the compiler says that it expects an expression. When I put an expression into the body of the loop, i.e.

while true:
  0

The compiler says that the expression is not used and refuses to compile my program. An obvious hack to that is to cast the expression to void, the expressions of this type get discarded.

while true:
  cast[void](0)

But now the compiler expects void as a parameter to the void cast


Solution

  • Use discard statement:

    while true:
      discard