Closed TonyP4N closed 11 months ago
To use a while loop, you need to use a method, like so:
method integer_squareroot(n: int) returns (res: int)
ensures res * res <= n
{
var x := 0;
var y := (x + 1) / 2;
while(y < x)
invariant y * y <= n
invariant x * x <= n
invariant y >= 0
{
x := y;
y := (x + n / x) / 2;
}
return x;
}
But I admit that the difference between allowed bodies for methods (allows statements) and functions (only allows an expression) can be surprising.
That makes sense, thank you very much!
Failing code
Steps to reproduce the issue
Actual behavior
always report invalid UnaryExpressionParser[p_generic_syntax_error] on the while key word