3

It seems that I cannot use a loop in Dynamic. Quite ridiculous??

Here is my minimal example:

Grid[{{Button["test", i = 0; While[i < 10, Pause[10]; i++]], InputField[Dynamic[i]]}}]

I expect the dynamic i will increase by one every ten seconds(10 seconds gap is set to prevent it goes too fast to be observed). But the truth is i just starts from 0 and stops when I click on the button.

Thanks for your attention! Any comments and suggestion will be very welcome.

Edit: Thanks to comments from Kuba, I am now able to let the button update the value of i in a loop, but it still fails to work if I put them in DynamicsModule after check some other related questions.

The minimal example is:

DynamicModule[{i = 0},  Grid[{{Button["test", i = 0; 
 While[i < 10, i++; Pause[1]; FinishDynamic[]], 
 Method -> "Queued"], 
InputField[Dynamic[i, UpdateInterval -> .5]]}}]]
Jake Pan
  • 526
  • 3
  • 10

0 Answers0