views:

129

answers:

3

I recently read about labelled statments in java and the ability to specify a label with the break and continue statements. What other languages support this sort of syntax ?

+4  A: 

Here's a list of languages with Java-like labels; i.e the ability to branch out of a labeled statement or block.

  • Java
  • Javascript
  • C# - C# supports goto <label>, but not break <label> or continue <label>.
  • Ada - using the exit <label> statement.
  • PL/SQL - using the exit <label> or continue <label> statements.

Here's a list of languages with a more general GO TO construct (or equivalent), allowing an application to branch to any label at the same syntactic level or outer level.

  • Pascal
  • FORTRAN - FORTRAN also has a "computed goto" in which the target label is selected at runtime, and an "assigned goto" which is a form of self-modifying code.
  • COBOL
  • C
  • C++

Many languages (also) support throwing and catching exceptions. This can be thought of as a generalized form of branch-to-label. However there are two important distinctions:

  • The "throw point" does not specify the location that will catch the exception (i.e. a label).
  • Control flow may branch out of the current procedure/function/method call.

(Ruby's throw / catch seems to have aspects of normal exception handling and labeled statements. However, I'm inclined to think that since the label does not need to be lexically scoped, this is closest to normal exception handling.)

please add more.

Stephen C
With C# (at least), it's not the same. The Java example in the question allows you to specify a label *with* the break or continue (ex: `break foo;`). C# does not support that.
Anthony Pegram
c# supports goto {label}, but not break {label} or continue {label}.
Naveen
It'd be quicker to list languages that provide neither goto nor labeled breaks. Python for one http://www.python.org/dev/peps/pep-3136/
Gunslinger47
Notably, the control of non-nested labeled breaks can be replicated with a return statement from a nested or anonymous function.
Gunslinger47
@Stephen: Ruby's throw/catch are not exception handlers (hence the clarification). Those are similar to labels, used for control flow. Ruby exception handlers are raise/rescue. See http://ruby-doc.org/core/classes/Kernel.html#M005933 and http://ruby-doc.org/core/classes/Kernel.html#M005934
Chubas
+1  A: 

Do you wan an exhaustive list? How are you going to award the answer? To whomever lists most?

Basic, Pascal, Perl, all assemblers, I woudl imaigine (do I get a point for each that I name?, ...

You might want to read

http://en.wikipedia.org/wiki/Goto

http://en.wikipedia.org/wiki/Unstructured_programming

http://en.wikipedia.org/wiki/Considered_harmful

LeonixSolutions
You might want to read the body of the question.
Tom Hawtin - tackline
A: 
  • C (and Objective-C by the property that it is a direct superset of c).
  • Intel x86 assembly
  • Python
MTS