# Problem with Label in a Do loop, "nolabel"

Can someone tell me why this code doesn't work and how to fix it ? Thanks.

k = 0;
Do[{
Label[top],
k = k + 1,
Print["k = ", k],
If[k < 4, Goto[top]]},
{10}]

k = 1

Hold[Goto[top]]

• related
– Kuba
Apr 1, 2014 at 12:07

Goto first scans any compound expression in which it appears directly, then scans compound expressions that enclose this one.
Your Goto - Label construction is part of the List so Mathematica fails to find the label. Taking this under consideration, the following will work:
k = 0;

• "any compound expression" does not read as CompoundExpression -- I think this is not so clear from the documentation. On these grounds I am reopening this question. If the community votes to close it again however I shall not intervene again. Jun 26, 2015 at 17:02