bumbread
bumbread

Reputation: 472

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

Upvotes: 1

Views: 712

Answers (1)

uran
uran

Reputation: 1336

Use discard statement:

while true:
  discard

Upvotes: 8

Related Questions