Colon

From Lazarus wiki
Jump to navigationJump to search

English (en) suomi (fi) français (fr) русский (ru) 中文(中国大陆) (zh_CN)

:


The symbol :, pronounced “colon”, is used in Pascal in several ways:

  • in an identifier declaration it separates the type
    • most notably in var sections
    • but also in const sections (in case of explicitely typed constants)
    • procedure and function parameters have a type, too
    • and return values of functions (including operator overloads)
    • as well as properties
    • in general, everywhere where a new identifier associated with some memory, is introduced (also custom structured type definitions)
  • in case selectors it closes a match-list
  • in label definitions the colon seperates the instruction from the label name
  • also some routines, especially the Str, write and writeLn procedures accept further parameters via colon separated arguments
  • Offset / segment separation under DOS Mem[$B800:$0000]

The following example shows the most prevalent usage scenarios:

program colonDemo(input, output, stderr);

procedure numberReport(const i: int64);
begin
	case i of
		low(i)..-1:
		begin
			writeLn('Your number is negative. ☹');
		end;
		1..high(i):
		begin
			// right aligns to a width of 24 characters
			writeLn(i:24);
		end;
		else
		begin
			writeLn('You''ve entered zero.');
		end;
	end;
end;

var
	i: int64;

begin
	writeLn('Enter a number:');
	readLn(i);
	numberReport(i);
end.

other remarks

  • Colon appears in the assignment operator :=.
  • In ASCII the character colon : has the value 58.



navigation bar: topic: Pascal symbols
single characters

+ (plus)  •  - (minus)  •  * (asterisk)  •  / (slash)
= (equal)  •  > (greater than)  •  < (less than)
. (period)  •  : (colon)  •  ; (semi colon)
^ (hat)  •  @ (at)
$ (dollar sign)  •  & (ampersand)  •  # (hash)
' (single quote)

character pairs

<> (not equal)  •  <= (less than or equal)  •  := (becomes)  •  >= (greater than or equal)

 •  >< (symmetric difference)  •  // (double slash)