FreePascal Information Logo Friend of FreePascal Compiler Title
Articles with Feedback, FPC News Library, PDF Collection, Mail Lists, Books, Newsgroups, IRC Open online discussion areas Research and Tutorials Tools, Compilers and Utilities Blurbs about us, advertising, etc.
Welcome to the FoFPC Pascal Language GOTO

goto


     The Goto keyword forces a jump to a given label.

     It should Never be used in modern code since it makes code very difficult to maintain.

     It is mostly used to force a termination of heavily nested code, where the logic to safely exit would be tortuous.

     Never jump into or out of try statements, or into a loop or conditional block.

{$GOTO ON} // one way to enable the GOTO keyword

var
  i : Integer;

label
  GotoLabel;

begin
  for i := 1 to 10 do begin
    Writeln('i = ',i);

    if i = 4 then Goto GotoLabel;   // Conditionally exit the loop
  end;

  Writeln('The loop finished OK');
GotoLabel:
  Writeln('Loop finished with i = ',i);
end.

Example

    Download Source IconDownload This Source for Free Pascal

Output

i = 1
i = 2
i = 3
i = 4
Loop finished with i = 4

See Also

Override, Procedure, Reintroduce, Result, Var, Virtual.
 Links and Products we find useful



ButtonGenerator.com
Valid XHTML 1.0 Transitional Internet Map
Programmer's Heaven
grat-i-fi-ca-tion - noun
the state of being gratified; great satisfaction.


"Wow! We are so pleased to see Friends of FreePascal Compiler ... with such a cool look and feel!"

"We like the fact you wrote all of the server scripts using FPC!"

Ian Wright
Codemasters
Locations of visitors to this page world map hits counter
Copyright 2009 by 3F, LLC. All rights reserved. Worldwide.
Your request was processed by server #3 in 0.001574 secs.

sponsor
Click to visit our paid sponsor