Why does this module return 11 (as expected) when 'Accept' is clicked:
blist = {{"Accept", 11}, {"Cancel", $Failed}};
thisWorks[] := Module[{buttons = {}},
Map[AppendTo[buttons, Button[#[[1]], DialogReturn[#[[2]]]]]&, blist];
Return@DialogInput[buttons, Modal->True]
];
while this module does not?
thisFails[] := Module[{i, n, buttons = {}},
For[i = 1; n = Length@blist, i <= n, i++,
AppendTo[buttons,
Button[blist[[i, 1]], DialogReturn[blist[[i, 2]]]]]];
Return@DialogInput[buttons, Modal->True]
];
Hold@DialogReturn does not work either, in fact, thisFails[] does not return if used.
(Not that anyone would EVER want to use a For loop, of course :)
InputForm @ buttonsinstead ofDialogInput.For/Do/Tableare not able to inject values of iterators into held expressions, andButtonisHoldRest. p.s.Returnis redundant. – Kuba Mar 27 '18 at 06:45