Sign up ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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

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

Goto::nolabel: Label top not found. >>

share|improve this question
related – Kuba Apr 1 '14 at 12:07

1 Answer 1

up vote 8 down vote accepted

According to the documentation center:

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;
  Label[top]; k = k + 1; Print["k = ", k]; If[k < 4, Goto[top]]
  }, {10}]
share|improve this answer
"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. – Mr.Wizard Jun 26 at 17:02

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.