Why "While•Wend" it does not work?

If I run

"Dim i as Integer = 1

While i <= x
x = x * i
i= i+1

Return x"

with x = 6 (for example, value passed by a Button) it doesn’t stop when i = 6 but goes on and on.

Anybody knows why?

Thank you

x gets bigger faster than i, is the answer.

1 Like

You can change your code to:

Dim i as Integer = 1
Dim mStop as Integer = x
While i <= mStop
x = x * i
i= i+1
Return x

Thank you, it worked. Although it muste be; While i < mStop in line 3.
Otherwise you get an error in excess by the amount of x * mStop + 1.

Yes, but mStop does not, and that is the limit