Difference between revisions of "Greater than"

From Free Pascal wiki
Jump to navigationJump to search
(10 intermediate revisions by 3 users not shown)
Line 1: Line 1:
The greater than symbol, '''''>''''' is used to compare whether the value on the left side of the symbol, exceeds that of the value to the right side of the symbol, and returns the boolean value of true or false as a result.
+
 
 +
{{Greater than}}
 +
 
 +
<div style="float:right; margin: 0 20px 10px 0; padding:40px; font-size:500%; font-family: Georgia; background-color: #f9f9f9; border: 2px solid #777777;"><nowiki> > </nowiki> </div>
 +
 
 +
In [[ASCII]], the character code decimal <syntaxhighlight lang="pascal" enclose="none">62</syntaxhighlight> (or [[Hexadecimal|hexadecimal]] <syntaxhighlight lang="pascal" enclose="none">3E</syntaxhighlight>) is defined to be <syntaxhighlight lang="pascal" enclose="none">></syntaxhighlight> (greater-than sign).
 +
 
 +
== comparison operator ==
 +
=== true greater than ===
 +
The greater than symbol <syntaxhighlight lang="pascal" enclose="none">></syntaxhighlight> is used to compare whether the value on the left side of the symbol, exceeds that of the value to the right side of the symbol.
 +
The [[expression]] results in a [[Boolean|<syntaxhighlight lang="pascal" enclose="none">boolean</syntaxhighlight> value]].
 +
 
 +
<syntaxhighlight lang="pascal" line highlight="15,21,27,37">
 +
program comparisonDemo(input, output, stderr);
 +
 
 +
type
 +
size = (tiny, small, medium, large, huge);
 +
 
 +
var
 +
n, m: longint;
 +
c, d: char;
 +
 
 +
begin
 +
// of course, integers can be compared
 +
n :=  2;
 +
m := -2;
 +
 +
if n > m then
 +
begin
 +
writeLn(n, ' > ', m);
 +
end;
 +
 +
// also enumerative types can be ordered
 +
if huge > medium then
 +
begin
 +
writeLn('huge is greater than medium');
 +
end;
 +
 +
// but the constants true and false are also comparable
 +
if true > false then
 +
begin
 +
writeLn('true is greater than false');
 +
end;
 +
 +
// characters stay in a relation to each other, too
 +
// (result depends on the used character set)
 +
c := 'a';
 +
d := 'Z';
 +
 +
if c > d then
 +
begin
 +
writeLn(c, ' > ', d);
 +
end;
 +
end.
 +
</syntaxhighlight>
 +
 
 +
All ordinal types can be compared to values of the same type.
 +
Integers can be compared to any integer.
 +
 
 +
<syntaxhighlight lang="pascal" line highlight="12,18">
 +
program comparisonSignedDemo(input, output, stderr);
 +
 
 +
var
 +
n: int64;
 +
m: qword;
 +
 
 +
begin
 +
n := -1; // n stored as %111...111
 +
m :=  2; // m stored as %000...010
 +
 +
// signed comparison
 +
if n > m then
 +
begin
 +
writeLn(n, ' > ', m);
 +
end;
 +
 +
// "unsigned" comparison
 +
if qword(n) > m then
 +
begin
 +
writeLn('qword(', n, ') > ', m);
 +
end;
 +
end.
 +
</syntaxhighlight>
 +
 
 +
=== greater than or equal to ===
 +
If the greater than symbol is followed by an [[Equal|equal sign]] <syntaxhighlight lang="pascal" enclose="none">>=</syntaxhighlight>, the comparison also results in [[True|<syntaxhighlight lang="pascal" enclose="none">true</syntaxhighlight>]] if both operands are equal to each other.
 +
 
 +
== bit shift operator ==
 +
Two consecutive greater-than signs <syntaxhighlight lang="pascal" enclose="none">>></syntaxhighlight> act as the [[Shr|<syntaxhighlight lang="pascal" enclose="none">shr</syntaxhighlight> operator]].
 +
 
 +
== template list ==
 +
In [[Generics|generic type]] definitions the template list is delimited by a closing <syntaxhighlight lang="pascal" enclose="none">></syntaxhighlight>.
  
 
{{Symbols}}
 
{{Symbols}}
 
[[Category:Symbols]]
 

Revision as of 09:05, 19 April 2019

English (en) suomi (fi) français (fr) русский (ru)

>

In ASCII, the character code decimal 62 (or hexadecimal 3E) is defined to be > (greater-than sign).

comparison operator

true greater than

The greater than symbol > is used to compare whether the value on the left side of the symbol, exceeds that of the value to the right side of the symbol. The expression results in a boolean value.

 1program comparisonDemo(input, output, stderr);
 2
 3type
 4	size = (tiny, small, medium, large, huge);
 5
 6var
 7	n, m: longint;
 8	c, d: char;
 9
10begin
11	// of course, integers can be compared
12	n :=  2;
13	m := -2;
14	
15	if n > m then
16	begin
17		writeLn(n, ' > ', m);
18	end;
19	
20	// also enumerative types can be ordered
21	if huge > medium then
22	begin
23		writeLn('huge is greater than medium');
24	end;
25	
26	// but the constants true and false are also comparable
27	if true > false then
28	begin
29		writeLn('true is greater than false');
30	end;
31	
32	// characters stay in a relation to each other, too
33	// (result depends on the used character set)
34	c := 'a';
35	d := 'Z';
36	
37	if c > d then
38	begin
39		writeLn(c, ' > ', d);
40	end;
41end.

All ordinal types can be compared to values of the same type. Integers can be compared to any integer.

 1program comparisonSignedDemo(input, output, stderr);
 2
 3var
 4	n: int64;
 5	m: qword;
 6
 7begin
 8	n := -1; // n stored as %111...111
 9	m :=  2; // m stored as %000...010
10	
11	// signed comparison
12	if n > m then
13	begin
14		writeLn(n, ' > ', m);
15	end;
16	
17	// "unsigned" comparison
18	if qword(n) > m then
19	begin
20		writeLn('qword(', n, ') > ', m);
21	end;
22end.

greater than or equal to

If the greater than symbol is followed by an equal sign >=, the comparison also results in true if both operands are equal to each other.

bit shift operator

Two consecutive greater-than signs >> act as the shr operator.

template list

In generic type definitions the template list is delimited by a closing >.


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)