Labels

Labels serve as targets for goto statements. Mark the desired statement with a label and colon like this:

label_identifier : statement

Before marking a statement, you must declare a label. Labels are declared in declaration part of unit or routine, similar to variables and constants. Declare labels using the keyword label:

label label1, ..., labeln;

Name of the label needs to be a valid identifier. The label declaration, marked statement, and goto statement must belong to the same block. Hence it is not possible to jump into or out of a procedure or function. Do not mark more than one statement in a block with the same label.

Here is an example of an infinite loop that calls the Beep procedure repeatedly:

label loop;
...
loop: 
  Beep;
  goto loop;
  Note : Label should be followed by end of line (CR) otherwise compiler will report an error.
label loop;
...
loop: Beep; // compiler will report an error
loop: // compiler will report an error
Copyright (c) 2002-2012 mikroElektronika. All rights reserved.
What do you think about this topic ? Send us feedback!
Want more examples and libraries? 
Find them on LibStock - A place for the code