Goto Statement

Use the goto statement to unconditionally jump to a local label — for more information, refer to Labels. Syntax of the goto statement is:

goto label_name;

This will transfer control to the location of a local label specified by label_name. The goto line can come before or after the label.

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.

You can use goto to break out from any level of nested control structures. Never jump into a loop or other structured statement, since this can have unpredictable effects.

Use of goto statement is generally discouraged as practically every algorithm can be realized without it, resulting in legible structured programs. One possible application of goto statement is breaking out from deeply nested control structures:

for (...) do
  begin
    for (...) do
      begin
        ...
        if (disaster) then goto Error;
        ...
      end;
  end;
 .
 .
 .
Error: // error handling code
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