# While stops running in a Dynamicmodule

DynamicModule[{pne = {0, 0}, ido = 0, a = {0, -0.40}, pr = 200,
dt = 0.1, pn = {0, 0}, vne = {0, 0}, vn, stop = 11},
ClickPane[
Framed @
Graphics[{
Orange, Dynamic @ Disk[pne, 4],
Green, Dynamic @ Arrow[{pne, (pne + vne)*1.5}]},
PlotRange -> pr],
With[{w = 1/5*(pne - MousePosition["Graphics"])},
ido = 0;
While[stop > 10,
ido = ido + 1;
vne = If[ido < 2, w + a*dt, vn + a*dt];
pne = If[ido < 2, pne + w*dt, pn + vne*dt];
If[pne[] < -195, vne = (vne - Normalize[vne]/2)*{1, -1}];
If[pne[] > 195, vne = (vne - Normalize[vne]/2)*{1, -1}];
If[pne[] < -195, vne = (vne - Normalize[vne]/2)*{-1, 1}];
If[pne[] > 195, vne = (vne - Normalize[vne]/2)*{-1, 1}];
vn = vne;
pn = pne;
stop = 1/2 Norm[vne]^2 + (pne[] + 195)*0.4;
Pause[.001]; FinishDynamic[]]] &]]


I've noticed, the While stops running after around 450 loops.

I can't figure it out what's the cause. Any help would be nice because I'm a beginner.

By measuring the time with the difference in AbsoluteTime from the beginning to the end of the While, I found it to be just less than 6 seconds. To increase this time, use at the beginning of the notebook, for instance,

SetOptions[\$FrontEndSession, DynamicEvaluationTimeout -> 60]


which will run for several thousand steps. My thanks to Szabolcs for the reference.

Internal progress of the DynamicModule can be tracked by placing t0 = AbsoluteTime[]; immediately before While, Dynamic[x, x = {AbsoluteTime[] - t0, ido, stop}]; immediately before Pause, and

Dynamic[x]


outside the DynamicModule.

(Note: In an earlier Update, I stated that the code would stop responding after six seconds. However, I resolved this issue by restarting Mathematica, and it has not recurred.)