In C, C++ and some dialects of BASIC, goto labels are declared with the syntax label:. I'm working on a language that uses name: type as the syntax for variable declarations, so I'd prefer if possible to use something a bit more distinctive for labels. I am or at some point was passingly familiar with many languages that use that syntax for variable declarations, but off the top of my head I can't recall a single one of them that doesn't ban goto (not looking to argue about whether that's a good or bad design decision, just noting it did take place in those cases), so I'm trying to figure out where to look for precedent on labels.

What other forms of syntax has been used for goto labels? Are there any criteria I might be overlooking in choosing one over another?

(I just remembered Ada is an exception. But it uses <<label>>, which doesn't mix well with the use of those symbols as C-style shift operators.)

  • 4
    – Zenon
    Feb 24, 2012 at 0:39
  • 3
    "What other syntax has been used for goto labels"? How about just line numbers?
    – user16764
    Feb 24, 2012 at 0:43
  • 3
    Excuse me, but this is 2012. Dijkstra's original short piece on the problems created by the GOTO statement is over forty (40) years old. Bohm & Jacopini's formal proof of its superfluousness is almost as old. Don Good's GYPSY language (late 1970s to early 1980s) demonstrated that significant applications could be developed, and formally proved correct (proof later confirmed by testing), entirely without GOTO statements. BLISS likewise had no GOTO (although it did have other things.) GOTO statements are UNNECESSARY. Why do you insist on messing up your language with them? (Yes, I rant.) Feb 25, 2012 at 3:27
  • 3
    "GOTO statements are UNNCESSARY." So is for, while, do-while, if and if-else. Switch and goto is all you need for control flow. :-) Feb 25, 2012 at 7:30
  • 2
    @Daniel: Nah. In "modern" programming languages, you can do flow control with exceptions and try/catch ;)
    – back2dos
    Feb 25, 2012 at 13:07

6 Answers 6


DOS batch scripts use :label.

// I personally would use >label. :)

  • You know, I actually quite like >label. I'm curious, did you get it from anywhere in particular, or was it off-the-cuff?
    – rwallace
    Feb 24, 2012 at 23:01
  • Nowhere particular, I just feel that > invokes thoughts of "start from here".
    – Fixpoint
    Feb 24, 2012 at 23:56

You could make label a keyword and use something like:

label foo;



if you want it to stand out more.

But as Mitch says, it really depends on what the rest of your language's syntax looks like.

There's an argument to be made that the label syntax shouldn't fit in cleanly with the rest of the language, so that goto labels stand out more. (That was the rationale for Ada's <<LABEL>> syntax.)


If you must use GOTO statements, even knowing that they are unnecessary and an open invitation to mess up your programs, then do what Ichbiah et al (the original designers of Ada) did: MAKE THE SYNTAX UGLY.

Make it stick out like a giant thumb with a really hideous fungal infection that has been smashed with a hammer. Make it EASY for the maintenance programmers to see it, so they will know that the author of the code they are asked to maintain was a total cretin, who needed to be forcibly transferred to the business school, rather than be allowed to matriculate in computer science, so they will be on the lookout for the not-quite-as-obvious idiot mistakes that are bound to be festering all through his alleged code.

Ichbiah admitted they did this, in so many words. The DoD specification for the language explicitly required that it contain a GOTO statement, because the DoD believed (wrongly, in my personal opinion) that the case against it had not been made solidly enough. They couldn't NOT put in a GOTO, but they could and did make it UGLY, to discourage its use. Most places that used Ada outlawed its use immediately, or at least required management signoff on each and every GOTO, to encourage programmer to find a GOTO-less alternative.

Something like ###--->>>LABEL<<<---### would work. The label must be on a line, with massive "decoration", all the way up against the left margin, and ALL BY ITSELF.

Or maybe something like --->>>LABEL ... HEREBEDRAGONS, where "HEREBEDRAGONS" is a reserved word in the language, and any variation on HEREBEDRAGONS that is not all uppper case is defined to be a fatal syntax error. Make it HARD and PAINFUL for the programmer to use it.

  • 1
    I actually like this philosophy not because I don't think goto is ever appropriate, but rather because I regard it as shouting CONTROL FLOW DOES NOT MATCH CONVENTIONAL PATTERNS. Wanting goto targets to appear nice and sedate would be like wanting a fire alarm to play pleasant music. Fire alarms should be unpleasant not because they shouldn't exist, but because on those rare occasions when their use is appropriate, they deserve attention.
    – supercat
    Mar 27, 2014 at 18:40

I am not sure where I am getting this from, but somehoew @<label>: feels natural to me.

But I also suspect the 'right' answer depends on what else is going on in your new language, syntax-wise.

  • Yeah, I'm using @foo for attributes, Java style, otherwise I'd give that serious consideration.
    – rwallace
    Feb 24, 2012 at 1:10

JavaScript does not have goto but it has labels:

outer:for(var i=0;i<10;++i) {...}

and yet it has:

{ outer:"value" }

and yet you can find there:

some? outer:"value";

In JavaScript 2.0 typed variables were added:

var some:int;

All this does not create any conflicts as ':' appears in different contexts.

  • 1
    True. But if the language allows declarations without var/val/auto, there could be an ambiguity: local: type; vs label: local;. Feb 25, 2012 at 8:06

How about [label]? For example,

Stack<Solution> partialSolutions = new Stack<Solution>();

if (partialSolutions.isEmpty()) {
    acceptedSolution = null;
    goto cleanup;

Solution sol = partialSolutions.pop();
switch (rand() % 3) {
    [0] // accept this
    acceptedSolution = sol;
    goto cleanup;

    [1] // reject this and try the next solution
    goto weirdSearch;

    [2] // try a derived solution
    goto weirdSearchSkipEmptyCheck;


I don't know of any language that uses this syntax, though it reminds me of sections in INI files.

Some other bad ideas:


These should all be easy to parse if your language is Java-like, since no other statement can begin with an infix operator.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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