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 CONST

const


     The Const keyword is used to start a section of constant definitions.

     The section is terminated by the next keyword in a program. Within the section, one or more constants may be defined. These can be a mixture of normal or typed constants or expressions.

     When passing data to a routine (function or procedure), you can prefix the parameter definition with Const if the value is never updated within the called routine. This improves performance, clarifies routine operation, and prevents accidental updates of the value.

Example

    Download Source IconDownload This Source for Free Pascal
 Const
  MAX_LINES = 3;
  CRUDE_PI  = 22/7;
  HELLO     = 'Hello World';
  LETTERS   = ['A'..'Z', 'a'..'z'];
  DECISION  = True;

var
  i : Integer;

begin
  // Display our crude value of Pi
  Writeln('Crude Pi = ',CRUDE_PI);

  // Say hello to the WOrld
  Writeln(HELLO);

  // Display MAX_LINES of data
  for i := 1 to MAX_LINES do begin
    // Do some checking - note that Char(i+64) = 'A'
    if DECISION and (Char(i+63) in LETTERS)
    then Writeln(Char(i+63),' is a letter')
    else Writeln(Char(i+63),' is not a letter');
  end;
end.

Output

Crude Pi =  3.1428571428571429E+0000
Hello World
@ is not a letter
A is a letter
B is a letter

See Also

Function, Out, Procedure, Type, Var.
 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.


"Friends of Free Pascal is, in my view, one of the best things to happen to FPC since the compiler first appeared"

Gary Funk
BoardWatch Magazine
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.199665 secs.

sponsor
This sponsor helps us with our documentation