# Aborting from a Dialog box

I'm trying to abort a While cycle, with a dialog box. I've tried the following:

res = 0;
res2 = "";
CreateDialog[{TextCell["Do you want to continue calculations?"],
Button["Proceed", DialogReturn[res2 = True]],
Button["Cancel", DialogReturn[res2 = Abort[]]]}];

While[True , res++; If[res > 10, res = -1]; res2];


However, this does not work. It's important that the Dialog window may be left opened while the While continues to 'work'.

I've tried this but I was unable to adapt that solution to my problem...

Any help would be appreciated.

• I see you have not accepted any of your questions' anwsers. Aren't they useful? Please take a tour to see how it works. – Kuba Jan 19 '15 at 10:46
• @Kuba thanks and sorry for the delay – An old man in the sea. Jan 19 '15 at 14:11

If you use SetDelayed then you loop will call Abort. With Set (=) res2 has not value at all. You can check it evaluating:

a =. ;
a = Abort[]

(*new cell*)

a

a


So:

res = 0;
res2 = "";

CreateDialog[{TextCell["Do you want to continue calculations?"],
Button["Proceed", DialogReturn[res2 = True]],
Button["Cancel", DialogReturn[res2 := Abort[]]]}];

While[True, res++; If[res > 10, res = -1]; res2];


will do what you need.