You need to use Module
option on return
myMod := Module[{i},
Do[
Return[1, Module],
{i, 3}
];
Print["test"]
]
and now
myMod
(* 1 *)
This is because Return
only returns from nearest enclosure, which was Do
in your case and not from the whole Module
unless you use the Module
second option to Return
. This is different from other languages that you might be familiar with.
See possible options here https://reference.wolfram.com/mathematica/ref/Return.html for more information.
update
To answer the question in comment below if Return has always worked this way?
Using V 2.2 of Mathematica, the Module
option was not supported since I get an error. So this option was added sometime after version 2.2. May be someone else knows when it was added.
ps. looking at bottom of the Return
help page, it says it was updated in 1996 (version 3.0), so I would assume this is when the option Module
was added.