Label (computer science)

Uses your system voice; voice and rate in settings.

Snapshot

≈ 4 min read

Names in other languages

No names in other languages are held for this entry yet.

Article bodies are English and are not machine-translated. A name in another language is not a translation of the article.

In programming languages, a label is a sequence of characters that identifies a location within source code. In most languages, labels take the form of an identifier, often followed by a punctuation character (e.g., a colon). In many high-level languages, the purpose of a label is to act as the destination of a GOTO statement. In assembly language, labels can be used anywhere an address can (for example, as the operand of a JMP or MOV instruction). Also in Pascal and its derived variations. Some languages, such as Fortran and BASIC, support numeric labels. Labels are also used to identify an entry point into a compiled sequence of statements (e.g., during debugging).

In programming languages, a label is a sequence of characters that identifies a location within source code. In most languages, labels take the form of an identifier, often followed by a punctuation character (e.g., a colon). In many high-level languages, the purpose of a label is to act as the destination of a GOTO statement. In assembly language, labels can be used anywhere an address can (for example, as the operand of a JMP or MOV instruction). Also in Pascal and its derived variations. Some languages, such as Fortran and BASIC, support numeric labels. Labels are also used to identify an entry point into a compiled sequence of statements (e.g., during debugging). void foo(int number) { if (number Here error is the label. The statement goto can be used to jump to a labeled statement in the code. After a goto , program execution continues with the statement after the label. switch (die) { default: printf("invalid\n"); break; case 1: case 3: case 5: printf("odd\n"); break; case 2: case 4: case 6: printf("even\n"); break; } Within a single switch statement, the integer constant associated with each case label must be unique. There may or may not be a default statement. There is no restriction on the order of the labels within a switch. The requirement that case labels values evaluate to integer constants gives the compiler more room for optimizations. top: //Label the outermost for-loop. for (var i = 0; i It also possible to use break statement to break out of the code blocks: top: { console.log("foo") console.log("bar") break top console.log("baz") } // Which would output: // > foo // > bar (let ((iteration NIL)) (tagbody start (print 'started) (setf iteration 0) increase (print iteration) (incf iteration 1) (go check) check (if (>= iteration 10) (go end) (go increase)) end (print 'done))) A second method utilizes the reader macros #n= and #n# , the former of which labels the object immediately following it, the latter refers to its evaluated value. Labels in this sense constitute rather an alternative to variables, with #n= declaring and initializing a “variable” and #n# accessing it. The placeholder n designates a chosen unsigned decimal integer identifying the label. (progn #1="hello" (print #1#)) Apart from that, some forms permit or mandate the declaration of a label for later referral, including the special form block which prescribes a naming, and the loop macro that can be identified by a named clause. Immediate departure from a named form is possible by using the return-from special operator. (block myblock (loop for iteration from 0 do (if (>= iteration 10) (return-from myblock 'done) (print iteration)))) (loop named myloop for iteration from 0 do (if (>= iteration 10) (return-from myloop 'done) (print iteration))) In a fashion similar to C, the macros case , ccase , ecase , typecase , ctypecase and etypecase define switch statements. (let ((my-value 5)) (case my-value (1 (print "one")) (2 (print "two")) ((3 4 5) (print "three four or five")) (otherwise (print "any other value")))) (let ((my-value 5)) (typecase my-value (list (print "a list")) (string (print "a string")) (number (print "a number")) (otherwise (print "any other type"))))

See also

Line number

References

Text derived from https://en.wikipedia.org/w/index.php?oldid=1309972637 under CC BY-SA 4.0; modifications have been made.

Sources cited in this revision

8 named source(s) extracted from the cited revision. A source with no author is shown by its publication; nothing is invented.