Integer comparison: Difference between revisions

Content added Content deleted
m (syntax highlighting fixup automation)
Line 21: Line 21:


=={{header|11l}}==
=={{header|11l}}==
<lang 11l>V a = Int(input(‘Enter value of a: ’))
<syntaxhighlight lang="11l">V a = Int(input(‘Enter value of a: ’))
V b = Int(input(‘Enter value of b: ’))
V b = Int(input(‘Enter value of b: ’))


Line 29: Line 29:
print(‘a is greater than b’)
print(‘a is greater than b’)
I a == b
I a == b
print(‘a is equal to b’)</lang>
print(‘a is equal to b’)</syntaxhighlight>


=={{header|360 Assembly}}==
=={{header|360 Assembly}}==
Input is done by a standard register 1 pointed parameter list.
Input is done by a standard register 1 pointed parameter list.
<lang 360asm>INTCOMP PROLOG
<syntaxhighlight lang="360asm">INTCOMP PROLOG
* Reg1=Addr(Addr(argA),Addr(argB))
* Reg1=Addr(Addr(argA),Addr(argB))
L 2,0(1) Reg2=Addr(argA)
L 2,0(1) Reg2=Addr(argA)
Line 65: Line 65:
A DS F 31-bit signed integer
A DS F 31-bit signed integer
B DS F 31-bit signed integer
B DS F 31-bit signed integer
END</lang>
END</syntaxhighlight>


=={{header|6502 Assembly}}==
=={{header|6502 Assembly}}==
Line 71: Line 71:
Specific OS/hardware routines for user input and printing are left unimplemented.
Specific OS/hardware routines for user input and printing are left unimplemented.
It should be noted that this is strictly an unsigned comparison.
It should be noted that this is strictly an unsigned comparison.
<lang 6502asm>Compare PHA ;push Accumulator onto stack
<syntaxhighlight lang="6502asm">Compare PHA ;push Accumulator onto stack
JSR GetUserInput ;routine not implemented
JSR GetUserInput ;routine not implemented
;integers to compare now in memory locations A and B
;integers to compare now in memory locations A and B
Line 85: Line 85:
A_equals_B: JSR DisplayAEqualsB ;routine not implemented
A_equals_B: JSR DisplayAEqualsB ;routine not implemented
Done: PLA ;restore Accumulator from stack
Done: PLA ;restore Accumulator from stack
RTS ;return from subroutine</lang>
RTS ;return from subroutine</syntaxhighlight>


=={{header|68000 Assembly}}==
=={{header|68000 Assembly}}==
Line 93: Line 93:


===Unsigned Comparison===
===Unsigned Comparison===
<lang 68000devpac>Compare:
<syntaxhighlight lang="68000devpac">Compare:
;integers to compare are in D0 and D1
;integers to compare are in D0 and D1
CMP.L D1,D0
CMP.L D1,D0
Line 118: Line 118:
Equal:
Equal:
dc.b "both are equal",0
dc.b "both are equal",0
even</lang>
even</syntaxhighlight>


===Signed Comparison===
===Signed Comparison===
<lang 68000devpac>Compare:
<syntaxhighlight lang="68000devpac">Compare:
;integers to compare are in D0 and D1
;integers to compare are in D0 and D1
CMP.L D1,D0
CMP.L D1,D0
Line 146: Line 146:
Equal:
Equal:
dc.b "both are equal",0
dc.b "both are equal",0
even</lang>
even</syntaxhighlight>


=={{header|8051 Assembly}}==
=={{header|8051 Assembly}}==
Input/output is specific to hardware; this code assumes the integers are in registers a and b.
Input/output is specific to hardware; this code assumes the integers are in registers a and b.
There is only one comparison instruction to use: 'not equal'.
There is only one comparison instruction to use: 'not equal'.
<lang asm>compare:
<syntaxhighlight lang="asm">compare:
push psw
push psw
cjne a, b, clt
cjne a, b, clt
Line 167: Line 167:
compare_:
compare_:
pop psw
pop psw
ret</lang>
ret</syntaxhighlight>
Testing for (a <= b) or (a >= b) can be performed by changing the jumps.
Testing for (a <= b) or (a >= b) can be performed by changing the jumps.


=={{header|8th}}==
=={{header|8th}}==
The user would put the numbers on the stack and then invoke 'compare':
The user would put the numbers on the stack and then invoke 'compare':
<lang forth>
<syntaxhighlight lang="forth">
: compare \ n m --
: compare \ n m --
2dup n:= if "They are equal" . cr then
2dup n:= if "They are equal" . cr then
2dup n:< if "First less than second" . cr then
2dup n:< if "First less than second" . cr then
n:> if "First greater than second" . cr then ;
n:> if "First greater than second" . cr then ;
</syntaxhighlight>
</lang>
Alternatively one could use the "n:cmp" word
Alternatively one could use the "n:cmp" word


Line 183: Line 183:
{{works with|aarch64-linux-gnu-as/qemu-aarch64}}
{{works with|aarch64-linux-gnu-as/qemu-aarch64}}
Compare once (<code>cmp x0, x1</code>) and use conditional branching (<code>b.eq</code> and <code>b.gt</code>).
Compare once (<code>cmp x0, x1</code>) and use conditional branching (<code>b.eq</code> and <code>b.gt</code>).
<lang ARM_Assembly>.equ STDOUT, 1
<syntaxhighlight lang="arm_assembly">.equ STDOUT, 1
.equ SVC_WRITE, 64
.equ SVC_WRITE, 64
.equ SVC_EXIT, 93
.equ SVC_EXIT, 93
Line 246: Line 246:
_exit:
_exit:
mov x8, #SVC_EXIT
mov x8, #SVC_EXIT
svc #0</lang>
svc #0</syntaxhighlight>


=={{header|ABAP}}==
=={{header|ABAP}}==
This works in ABAP version 7.40 and above. Note that empty input is evaluated to 0.
This works in ABAP version 7.40 and above. Note that empty input is evaluated to 0.


<syntaxhighlight lang="abap">
<lang ABAP>
report z_integer_comparison.
report z_integer_comparison.


Line 265: Line 265:


write comparison_result.
write comparison_result.
</syntaxhighlight>
</lang>


=={{header|Action!}}==
=={{header|Action!}}==
<syntaxhighlight lang=Action!>PROC Main()
<syntaxhighlight lang="action!">PROC Main()
INT a,b
INT a,b


Line 293: Line 293:


=={{header|Ada}}==
=={{header|Ada}}==
<lang ada>with Ada.Text_IO; use Ada.Text_IO;
<syntaxhighlight lang="ada">with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_Io;
with Ada.Integer_Text_IO; use Ada.Integer_Text_Io;


Line 316: Line 316:
Put_Line("A is greater than B");
Put_Line("A is greater than B");
end if;
end if;
end Compare_Ints;</lang>
end Compare_Ints;</syntaxhighlight>


=={{header|Aime}}==
=={{header|Aime}}==
<lang aime>void
<syntaxhighlight lang="aime">void
output(integer a, integer b, text condition)
output(integer a, integer b, text condition)
{
{
Line 345: Line 345:


return 0;
return 0;
}</lang>
}</syntaxhighlight>
Run as:
Run as:
<pre>aime FILE integer a 33 integer b 133</pre>
<pre>aime FILE integer a 33 integer b 133</pre>
Line 363: Line 363:
The above distributions of both [[ALGOL 68G]] and [[ELLA ALGOL 68]] compilers only
The above distributions of both [[ALGOL 68G]] and [[ELLA ALGOL 68]] compilers only
allow [[wp:ASCII|ASCII]] characters (ASCII has neither "&le;", "&ge;" nor "&ne;" characters).
allow [[wp:ASCII|ASCII]] characters (ASCII has neither "&le;", "&ge;" nor "&ne;" characters).
<lang algol68>main: (
<syntaxhighlight lang="algol68">main: (
INT a, b;
INT a, b;
read((a, space, b, new line));
read((a, space, b, new line));
Line 383: Line 383:
print((a," is greater or equal to ", b, new line))
print((a," is greater or equal to ", b, new line))
FI
FI
)</lang>
)</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 392: Line 392:


=={{header|ALGOL W}}==
=={{header|ALGOL W}}==
<lang algolw>begin
<syntaxhighlight lang="algolw">begin


integer a, b;
integer a, b;
Line 405: Line 405:
if a > b then write( a, " is greater than ", b );
if a > b then write( a, " is greater than ", b );


end.</lang>
end.</syntaxhighlight>


=={{header|AppleScript}}==
=={{header|AppleScript}}==
<lang AppleScript>set n1 to text returned of (display dialog "Enter the first number:" default answer "") as integer
<syntaxhighlight lang="applescript">set n1 to text returned of (display dialog "Enter the first number:" default answer "") as integer
set n2 to text returned of (display dialog "Enter the second number:" default answer "") as integer
set n2 to text returned of (display dialog "Enter the second number:" default answer "") as integer
set msg to {n1}
set msg to {n1}
Line 419: Line 419:
end if
end if
set end of msg to n2
set end of msg to n2
return msg as string</lang>
return msg as string</syntaxhighlight>


Or...
Or...
<lang AppleScript>set n1 to text returned of (display dialog "Enter the first number:" default answer "") as integer
<syntaxhighlight lang="applescript">set n1 to text returned of (display dialog "Enter the first number:" default answer "") as integer
set n2 to text returned of (display dialog "Enter the second number:" default answer "") as integer
set n2 to text returned of (display dialog "Enter the second number:" default answer "") as integer
if n1 < n2 then return "" & n1 & " is less than " & n2
if n1 < n2 then return "" & n1 & " is less than " & n2
if n1 = n2 then return "" & n1 & " is equal to " & n2
if n1 = n2 then return "" & n1 & " is equal to " & n2
if n1 > n2 then return "" & n1 & " is greater than " & n2</lang>
if n1 > n2 then return "" & n1 & " is greater than " & n2</syntaxhighlight>


=={{header|ARM Assembly}}==
=={{header|ARM Assembly}}==
{{works with|as|Raspberry Pi}}
{{works with|as|Raspberry Pi}}
<syntaxhighlight lang="arm assembly">
<lang ARM Assembly>


/* ARM assembly Raspberry PI */
/* ARM assembly Raspberry PI */
Line 614: Line 614:
szMessErrDep: .asciz "Too large: overflow 32 bits.\n"
szMessErrDep: .asciz "Too large: overflow 32 bits.\n"


</syntaxhighlight>
</lang>


=={{header|Arturo}}==
=={{header|Arturo}}==
<syntaxhighlight lang=rebol>a: to :integer input "enter a value for a: "
<syntaxhighlight lang="rebol">a: to :integer input "enter a value for a: "
b: to :integer input "enter a value for b: "
b: to :integer input "enter a value for b: "


Line 625: Line 625:


=={{header|Astro}}==
=={{header|Astro}}==
<lang python>let a = input('Enter value of a: ')
<syntaxhighlight lang="python">let a = input('Enter value of a: ')
let b = input('Enter value of b: ')
let b = input('Enter value of b: ')


Line 633: Line 633:
print 'a is greater than b'
print 'a is greater than b'
elif a == b:
elif a == b:
print 'a is equal to b'</lang>
print 'a is equal to b'</syntaxhighlight>


=={{header|AutoHotkey}}==
=={{header|AutoHotkey}}==
Error checking is performed automatically by attaching UpDowns to each of the Edit controls. UpDown controls always yield an in-range number, even when the user has typed something non-numeric or out-of-range in the Edit control.
Error checking is performed automatically by attaching UpDowns to each of the Edit controls. UpDown controls always yield an in-range number, even when the user has typed something non-numeric or out-of-range in the Edit control.
The default range is 0 to 100.
The default range is 0 to 100.
<lang autohotkey>Gui, Add, Edit
<syntaxhighlight lang="autohotkey">Gui, Add, Edit
Gui, Add, UpDown, vVar1
Gui, Add, UpDown, vVar1
Gui, Add, Edit
Gui, Add, Edit
Line 657: Line 657:


GuiClose:
GuiClose:
ExitApp</lang>
ExitApp</syntaxhighlight>


=={{header|Avail}}==
=={{header|Avail}}==
<lang Avail>// This code doesn't try to protect against any malformed input.
<syntaxhighlight lang="avail">// This code doesn't try to protect against any malformed input.
a ::= next line from standard input→integer;
a ::= next line from standard input→integer;
b ::= next line from standard input→integer;
b ::= next line from standard input→integer;
If a > b then [Print: "a > b";]
If a > b then [Print: "a > b";]
else if a < b then [Print: "a < b";]
else if a < b then [Print: "a < b";]
else if a = b then [Print: "a = b";];</lang>
else if a = b then [Print: "a = b";];</syntaxhighlight>


=={{header|AWK}}==
=={{header|AWK}}==
<lang awk>/[0-9]* [0-9]*/{
<syntaxhighlight lang="awk">/[0-9]* [0-9]*/{
if ($1 == $2) print $1, "is equal to", $2
if ($1 == $2) print $1, "is equal to", $2
if ($1 < $2) print $1, "is less than", $2
if ($1 < $2) print $1, "is less than", $2
if ($1 > $2) print $1, "is greater than", $2
if ($1 > $2) print $1, "is greater than", $2
}</lang>
}</syntaxhighlight>


In awk, a double equals symbol is required to test for equality.
In awk, a double equals symbol is required to test for equality.
A single equals sign is used for assignment, and will cause a bug if it is used within a boolean expression:
A single equals sign is used for assignment, and will cause a bug if it is used within a boolean expression:


<lang awk># This code contains a bug
<syntaxhighlight lang="awk"># This code contains a bug
IF (n=3) PRINT "n is equal to 3" # The incorrectly used equals sign will set n to a value of 3</lang>
IF (n=3) PRINT "n is equal to 3" # The incorrectly used equals sign will set n to a value of 3</syntaxhighlight>


=={{header|Axe}}==
=={{header|Axe}}==
<lang axe>Lbl FUNC
<syntaxhighlight lang="axe">Lbl FUNC
If r₁<r₂
If r₁<r₂
Disp "LESS THAN",i
Disp "LESS THAN",i
Line 691: Line 691:
Disp "GREATER THAN",i
Disp "GREATER THAN",i
End
End
Return</lang>
Return</syntaxhighlight>


=={{header|BASIC}}==
=={{header|BASIC}}==


==={{header|BaCon}}===
==={{header|BaCon}}===
<lang freebasic>
<syntaxhighlight lang="freebasic">
INPUT "Enter first number " ,a
INPUT "Enter first number " ,a
INPUT "Enter second number " ,b
INPUT "Enter second number " ,b
IF a < b THEN PRINT a ," is less than ", b
IF a < b THEN PRINT a ," is less than ", b
IF a = b THEN PRINT a, " is equal to ", b
IF a = b THEN PRINT a, " is equal to ", b
IF a > b THEN PRINT a, " is greater than ", b</lang>
IF a > b THEN PRINT a, " is greater than ", b</syntaxhighlight>




{{works with|QuickBasic|4.5}}
{{works with|QuickBasic|4.5}}
<lang qbasic>CLS
<syntaxhighlight lang="qbasic">CLS
INPUT "a, b"; a, b 'remember to type the comma when you give the numbers
INPUT "a, b"; a, b 'remember to type the comma when you give the numbers
PRINT "a is ";
PRINT "a is ";
Line 711: Line 711:
IF a = b THEN PRINT "equal to ";
IF a = b THEN PRINT "equal to ";
IF a > b THEN PRINT "greater than ";
IF a > b THEN PRINT "greater than ";
PRINT "b"</lang>
PRINT "b"</syntaxhighlight>


==={{header|Applesoft BASIC}}===
==={{header|Applesoft BASIC}}===
<lang ApplesoftBasic>10 INPUT "ENTER TWO INTEGERS: "; A%, B%
<syntaxhighlight lang="applesoftbasic">10 INPUT "ENTER TWO INTEGERS: "; A%, B%
20 A$(0) = "NOT "
20 A$(0) = "NOT "
30 PRINT A% " IS " A$(A% < B%) "LESS THAN " B%
30 PRINT A% " IS " A$(A% < B%) "LESS THAN " B%
40 PRINT A% " IS " A$(A% = B%) "EQUAL TO " B%
40 PRINT A% " IS " A$(A% = B%) "EQUAL TO " B%
50 PRINT A% " IS " A$(A% > B%) "GREATER THAN " B%</lang>
50 PRINT A% " IS " A$(A% > B%) "GREATER THAN " B%</syntaxhighlight>


==={{header|IS-BASIC}}===
==={{header|IS-BASIC}}===
<lang IS-BASIC>100 INPUT PROMPT "Enter A: ":A
<syntaxhighlight lang="is-basic">100 INPUT PROMPT "Enter A: ":A
110 INPUT PROMPT "Enter B: ":B
110 INPUT PROMPT "Enter B: ":B
120 IF A<B THEN
120 IF A<B THEN
Line 729: Line 729:
160 ELSE
160 ELSE
170 PRINT A;"is greater than ";B
170 PRINT A;"is greater than ";B
180 END IF</lang>
180 END IF</syntaxhighlight>


or
or


<lang IS-BASIC>100 INPUT PROMPT "Enter A: ":A
<syntaxhighlight lang="is-basic">100 INPUT PROMPT "Enter A: ":A
110 INPUT PROMPT "Enter B: ":B
110 INPUT PROMPT "Enter B: ":B
120 SELECT CASE A
120 SELECT CASE A
Line 742: Line 742:
170 CASE ELSE
170 CASE ELSE
180 PRINT A;"is greater than ";B
180 PRINT A;"is greater than ";B
190 END SELECT</lang>
190 END SELECT</syntaxhighlight>


==={{header|BASIC256}}===
==={{header|BASIC256}}===
<lang freebasic>input "Please enter one integer: ", x
<syntaxhighlight lang="freebasic">input "Please enter one integer: ", x
input "and a second integer: ", y
input "and a second integer: ", y


if x < y then print x; " is less than "; y
if x < y then print x; " is less than "; y
if x = y then print x; " is equal to "; y
if x = y then print x; " is equal to "; y
if x > y then print x; " is greater than "; y</lang>
if x > y then print x; " is greater than "; y</syntaxhighlight>


==={{header|OxygenBasic}}===
==={{header|OxygenBasic}}===
<lang>
<syntaxhighlight lang="text">
uses console
uses console
print "Integer comparison. (press ctrl-c to exit) " cr cr
print "Integer comparison. (press ctrl-c to exit) " cr cr
Line 768: Line 768:
endif
endif
loop
loop
</syntaxhighlight>
</lang>


==={{header|QBasic}}===
==={{header|QBasic}}===
<lang qbasic>INPUT "Please enter two integers, separated by a comma: ", x, y
<syntaxhighlight lang="qbasic">INPUT "Please enter two integers, separated by a comma: ", x, y


IF x < y THEN PRINT x; " is less than "; y
IF x < y THEN PRINT x; " is less than "; y
IF x = y THEN PRINT x; " is equal to "; y
IF x = y THEN PRINT x; " is equal to "; y
IF x > y THEN PRINT x; " is greater than "; y</lang>
IF x > y THEN PRINT x; " is greater than "; y</syntaxhighlight>


==={{header|True BASIC}}===
==={{header|True BASIC}}===
<lang qbasic>PRINT "Please enter two integers, separated by a comma: ";
<syntaxhighlight lang="qbasic">PRINT "Please enter two integers, separated by a comma: ";
INPUT x, y
INPUT x, y


Line 784: Line 784:
IF x = y THEN PRINT x; " is equal to "; y
IF x = y THEN PRINT x; " is equal to "; y
IF x > y THEN PRINT x; " is greater than "; y
IF x > y THEN PRINT x; " is greater than "; y
END</lang>
END</syntaxhighlight>


==={{header|Yabasic}}===
==={{header|Yabasic}}===
<lang yabasic>input "Please enter two integers, separated by a comma: " x, y
<syntaxhighlight lang="yabasic">input "Please enter two integers, separated by a comma: " x, y


if x < y then print x, " is less than ", y : fi
if x < y then print x, " is less than ", y : fi
if x = y then print x, " is equal to ", y : fi
if x = y then print x, " is equal to ", y : fi
if x > y then print x, " is greater than ", y : fi</lang>
if x > y then print x, " is greater than ", y : fi</syntaxhighlight>


==={{Header|Tiny BASIC}}===
==={{Header|Tiny BASIC}}===
<lang tinybasic>PRINT "Enter a number"
<syntaxhighlight lang="tinybasic">PRINT "Enter a number"
INPUT A
INPUT A
PRINT "Enter another number"
PRINT "Enter another number"
Line 800: Line 800:
IF A < B THEN PRINT A," is less than ",B
IF A < B THEN PRINT A," is less than ",B
IF A > B THEN PRINT A," is greater than ",B
IF A > B THEN PRINT A," is greater than ",B
IF A = B THEN PRINT A," is equal to ",B</lang>
IF A = B THEN PRINT A," is equal to ",B</syntaxhighlight>


=={{header|Batch File}}==
=={{header|Batch File}}==
<lang dos>@echo off
<syntaxhighlight lang="dos">@echo off
setlocal EnableDelayedExpansion
setlocal EnableDelayedExpansion
set /p a="A: "
set /p a="A: "
Line 813: Line 813:
) else ( if %a% EQU %b% (
) else ( if %a% EQU %b% (
echo %a% is equal to %b%
echo %a% is equal to %b%
)))</lang>
)))</syntaxhighlight>
{{Out}}
{{Out}}
<pre>C:\Test>IntegerComparison.bat
<pre>C:\Test>IntegerComparison.bat
Line 821: Line 821:


=={{header|BBC BASIC}}==
=={{header|BBC BASIC}}==
<lang bbcbasic> INPUT "Enter two numbers separated by a comma: " a, b
<syntaxhighlight lang="bbcbasic"> INPUT "Enter two numbers separated by a comma: " a, b
CASE TRUE OF
CASE TRUE OF
WHEN a < b: PRINT ;a " is less than "; b
WHEN a < b: PRINT ;a " is less than "; b
WHEN a = b: PRINT ;a " is equal to "; b
WHEN a = b: PRINT ;a " is equal to "; b
WHEN a > b: PRINT ;a " is greater than "; b
WHEN a > b: PRINT ;a " is greater than "; b
ENDCASE</lang>
ENDCASE</syntaxhighlight>


=={{header|bc}}==
=={{header|bc}}==
{{Works with|GNU bc}}
{{Works with|GNU bc}}
(POSIX bc doesn't have I/O functions/statements (i.e. <code>read</code> and <code>print</code>) but the rest of the code would work.)
(POSIX bc doesn't have I/O functions/statements (i.e. <code>read</code> and <code>print</code>) but the rest of the code would work.)
<lang bc>a = read()
<syntaxhighlight lang="bc">a = read()
b = read()
b = read()
if (a < b) print "a is smaller than b\n"
if (a < b) print "a is smaller than b\n"
if (a > b) print "a is greater than b\n"
if (a > b) print "a is greater than b\n"
if (a == b) print "a is equal to b\n"
if (a == b) print "a is equal to b\n"
quit</lang>
quit</syntaxhighlight>


=={{header|Befunge}}==
=={{header|Befunge}}==
Line 842: Line 842:
The branch commands (underline _ and pipe |) test for zero.
The branch commands (underline _ and pipe |) test for zero.


<lang befunge>v v ">" $<
<syntaxhighlight lang="befunge">v v ">" $<
>&&"=A",,\:."=B ",,,\: .55+,-:0`|
>&&"=A",,\:."=B ",,,\: .55+,-:0`|
v "<" _v#<
v "<" _v#<
@,+55,," B",,,"A " < "=" <</lang>
@,+55,," B",,,"A " < "=" <</syntaxhighlight>


=={{header|BQN}}==
=={{header|BQN}}==
The function <code>Comp</code> compares two integers and returns the appropriate string result.
The function <code>Comp</code> compares two integers and returns the appropriate string result.


<lang bqn> Comp ← ⊑·/⟜"Greater than"‿"Equal To"‿"Lesser Than"(>∾=∾<)
<syntaxhighlight lang="bqn"> Comp ← ⊑·/⟜"Greater than"‿"Equal To"‿"Lesser Than"(>∾=∾<)
⊑(/⟜⟨ "Greater than" "Equal To" "Lesser Than" ⟩>∾=∾<)
⊑(/⟜⟨ "Greater than" "Equal To" "Lesser Than" ⟩>∾=∾<)
Line 858: Line 858:
"Equal To"
"Equal To"
6 Comp 5
6 Comp 5
"Greater than"</lang>
"Greater than"</syntaxhighlight>




=={{header|Bracmat}}==
=={{header|Bracmat}}==
<lang bracmat> get$:?A
<syntaxhighlight lang="bracmat"> get$:?A
& get$:?B
& get$:?B
& (!A:!B&out$"A equals B"|)
& (!A:!B&out$"A equals B"|)
& (!A:<!B&out$"A is less than B"|)
& (!A:<!B&out$"A is less than B"|)
& (!A:>!B&out$"A is greater than B"|);</lang>
& (!A:>!B&out$"A is greater than B"|);</syntaxhighlight>


=={{header|Brat}}==
=={{header|Brat}}==
<lang brat>first = ask("First integer: ").to_i
<syntaxhighlight lang="brat">first = ask("First integer: ").to_i
second = ask("Second integer: ").to_i
second = ask("Second integer: ").to_i


when { first > second } { p "#{first} is greater than #{second}" }
when { first > second } { p "#{first} is greater than #{second}" }
{ first < second } { p "#{first} is less than #{second}" }
{ first < second } { p "#{first} is less than #{second}" }
{ first == second } { p "#{first} is equal to #{second}" }</lang>
{ first == second } { p "#{first} is equal to #{second}" }</syntaxhighlight>


=={{header|Burlesque}}==
=={{header|Burlesque}}==


<lang burlesque>
<syntaxhighlight lang="burlesque">
blsq ) "5 6"ps^pcm+.{"The first one is less than the second one""They are both equal""The second one is less than the first one"}\/!!sh
blsq ) "5 6"ps^pcm+.{"The first one is less than the second one""They are both equal""The second one is less than the first one"}\/!!sh
The first one is less than the second one
The first one is less than the second one
Line 885: Line 885:
blsq ) "6 5"ps^pcm+.{"The first one is less than the second one""They are both equal""The second one is less than the first one"}\/!!sh
blsq ) "6 5"ps^pcm+.{"The first one is less than the second one""They are both equal""The second one is less than the first one"}\/!!sh
The second one is less than the first one
The second one is less than the first one
</syntaxhighlight>
</lang>


=={{header|C}}==
=={{header|C}}==
<lang c>#include <stdio.h>
<syntaxhighlight lang="c">#include <stdio.h>


int main()
int main()
Line 905: Line 905:


return 0;
return 0;
}</lang>
}</syntaxhighlight>


=={{header|C sharp|C#}}==
=={{header|C sharp|C#}}==
<lang csharp>using System;
<syntaxhighlight lang="csharp">using System;


class Program
class Program
Line 923: Line 923:
Console.WriteLine("{0} is greater than {1}", a, b);
Console.WriteLine("{0} is greater than {1}", a, b);
}
}
}</lang>
}</syntaxhighlight>


=={{header|C++}}==
=={{header|C++}}==
<lang cpp>#include <iostream>
<syntaxhighlight lang="cpp">#include <iostream>


int main()
int main()
Line 948: Line 948:
if (a > b)
if (a > b)
std::cout << a << " is greater than " << b << "\n";
std::cout << a << " is greater than " << b << "\n";
}</lang>
}</syntaxhighlight>


=={{header|CFEngine}}==
=={{header|CFEngine}}==
<lang cfengine3>
<syntaxhighlight lang="cfengine3">
bundle agent __main__
bundle agent __main__
{
{
Line 967: Line 967:
if => isgreaterthan( "$(first_integer)", "$(second_integer)" );
if => isgreaterthan( "$(first_integer)", "$(second_integer)" );
}
}
</syntaxhighlight>
</lang>


=={{header|ChucK}}==
=={{header|ChucK}}==
<lang>
<syntaxhighlight lang="text">
fun void intComparison (int one, int two)
fun void intComparison (int one, int two)
{
{
Line 979: Line 979:
// uncomment next line and change values to test
// uncomment next line and change values to test
// intComparison (2,4);
// intComparison (2,4);
</syntaxhighlight>
</lang>


=={{header|Clean}}==
=={{header|Clean}}==
<lang clean>import StdEnv
<syntaxhighlight lang="clean">import StdEnv


compare a b
compare a b
Line 993: Line 993:
(_, a, console) = freadi console
(_, a, console) = freadi console
(_, b, console) = freadi console
(_, b, console) = freadi console
= compare a b</lang>
= compare a b</syntaxhighlight>


=={{header|Clipper}}==
=={{header|Clipper}}==
<lang clipper> Function Compare(a, b)
<syntaxhighlight lang="clipper"> Function Compare(a, b)
IF a < b
IF a < b
? "A is less than B"
? "A is less than B"
Line 1,005: Line 1,005:
ENDIF
ENDIF
Return Nil
Return Nil
</syntaxhighlight>
</lang>


=={{header|Clojure}}==
=={{header|Clojure}}==
Line 1,011: Line 1,011:
It evaluates the when/println body three times, each time with op and string bound to their corresponding entries in the list of three operator/string pairs.
It evaluates the when/println body three times, each time with op and string bound to their corresponding entries in the list of three operator/string pairs.
Note that this does no validation on input: if the user inputs a string then an exception will be thrown.
Note that this does no validation on input: if the user inputs a string then an exception will be thrown.
<lang Clojure>(let [[a b] (repeatedly read)]
<syntaxhighlight lang="clojure">(let [[a b] (repeatedly read)]
(doseq [[op string] [[< "less than"]
(doseq [[op string] [[< "less than"]
[> "greater than"]
[> "greater than"]
[= "equal to"]]]
[= "equal to"]]]
(when (op a b)
(when (op a b)
(println (str a " is " string " " b)))))</lang>
(println (str a " is " string " " b)))))</syntaxhighlight>


=={{header|CMake}}==
=={{header|CMake}}==
<lang cmake># Define A and B as integers. For example:
<syntaxhighlight lang="cmake"># Define A and B as integers. For example:
# cmake -DA=3 -DB=5 -P compare.cmake
# cmake -DA=3 -DB=5 -P compare.cmake


Line 1,037: Line 1,037:
if(A GREATER B)
if(A GREATER B)
message(STATUS "${A} is greater than ${B}")
message(STATUS "${A} is greater than ${B}")
endif()</lang>
endif()</syntaxhighlight>


=={{header|COBOL}}==
=={{header|COBOL}}==
{{works with|OpenCOBOL}}
{{works with|OpenCOBOL}}
<lang cobol> IDENTIFICATION DIVISION.
<syntaxhighlight lang="cobol"> IDENTIFICATION DIVISION.
PROGRAM-ID. Int-Compare.
PROGRAM-ID. Int-Compare.


Line 1,066: Line 1,066:


GOBACK
GOBACK
.</lang>
.</syntaxhighlight>


=={{header|ColdFusion}}==
=={{header|ColdFusion}}==
Line 1,079: Line 1,079:
===In CFML===
===In CFML===


<lang cfm><cffunction name="CompareInteger">
<syntaxhighlight lang="cfm"><cffunction name="CompareInteger">
<cfargument name="Integer1" type="numeric">
<cfargument name="Integer1" type="numeric">
<cfargument name="Integer2" type="numeric">
<cfargument name="Integer2" type="numeric">
Line 1,102: Line 1,102:
</cfif>
</cfif>
<cfreturn VARIABLES.Result >
<cfreturn VARIABLES.Result >
</cffunction></lang>
</cffunction></syntaxhighlight>


===In CFScript===
===In CFScript===


<lang cfm><cfscript>
<syntaxhighlight lang="cfm"><cfscript>
function CompareInteger( Integer1, Integer2 ) {
function CompareInteger( Integer1, Integer2 ) {
VARIABLES.Result = "";
VARIABLES.Result = "";
Line 1,129: Line 1,129:
return VARIABLES.Result;
return VARIABLES.Result;
}
}
</cfscript></lang>
</cfscript></syntaxhighlight>


=={{header|Common Lisp}}==
=={{header|Common Lisp}}==
You can type this directly into a REPL:
You can type this directly into a REPL:


<lang lisp>(let ((a (read *standard-input*))
<syntaxhighlight lang="lisp">(let ((a (read *standard-input*))
(b (read *standard-input*)))
(b (read *standard-input*)))
(cond
(cond
Line 1,142: Line 1,142:
((> a b) (format t "~A is greater than ~A." a b))
((> a b) (format t "~A is greater than ~A." a b))
((= a b) (format t "~A is equal to ~A." a b))
((= a b) (format t "~A is equal to ~A." a b))
(t (format t "Cannot determine relevance between ~A and ~B!" a b)))))</lang>
(t (format t "Cannot determine relevance between ~A and ~B!" a b)))))</syntaxhighlight>


After hitting enter, the REPL is expecting the two numbers right away.
After hitting enter, the REPL is expecting the two numbers right away.
Line 1,148: Line 1,148:
Alternatively, you can wrap this code in a function definition:
Alternatively, you can wrap this code in a function definition:


<lang lisp>(defun compare-integers ()
<syntaxhighlight lang="lisp">(defun compare-integers ()
(let ((a (read *standard-input*))
(let ((a (read *standard-input*))
(b (read *standard-input*)))
(b (read *standard-input*)))
Line 1,157: Line 1,157:
((> a b) (format t "~A is greater than ~A." a b))
((> a b) (format t "~A is greater than ~A." a b))
((= a b) (format t "~A is equal to ~A." a b))
((= a b) (format t "~A is equal to ~A." a b))
(t (format t "Cannot determine relevance between ~A and ~B!" a b)))))</lang>
(t (format t "Cannot determine relevance between ~A and ~B!" a b)))))</syntaxhighlight>


Then, execute the function for better control:
Then, execute the function for better control:
Line 1,166: Line 1,166:


If you run this program, it will halt awaiting user input. Toggle in the value of <math>x</math>, then click <tt>Enter</tt>, then toggle in <math>y</math>, then <tt>Enter</tt>, and then <tt>Run</tt>. <math>x</math> and <math>y</math> must both be unsigned eight-bit integers. The computer will halt with the accumulator storing 1 if <math>x</math>><math>y</math>, 0 if <math>x</math>=<math>y</math>, or -1 if <math>x</math><<math>y</math>; and it will be ready for a fresh pair of integers to be entered.
If you run this program, it will halt awaiting user input. Toggle in the value of <math>x</math>, then click <tt>Enter</tt>, then toggle in <math>y</math>, then <tt>Enter</tt>, and then <tt>Run</tt>. <math>x</math> and <math>y</math> must both be unsigned eight-bit integers. The computer will halt with the accumulator storing 1 if <math>x</math>><math>y</math>, 0 if <math>x</math>=<math>y</math>, or -1 if <math>x</math><<math>y</math>; and it will be ready for a fresh pair of integers to be entered.
<lang czasm>start: STP ; get input
<syntaxhighlight lang="czasm">start: STP ; get input


x: NOP
x: NOP
Line 1,193: Line 1,193:
JMP start
JMP start


one: 1</lang>
one: 1</syntaxhighlight>


=={{header|D}}==
=={{header|D}}==
<lang d>void main() {
<syntaxhighlight lang="d">void main() {
import std.stdio, std.conv, std.string;
import std.stdio, std.conv, std.string;


Line 1,213: Line 1,213:
if (a > b)
if (a > b)
writeln(a, " is greater than ", b);
writeln(a, " is greater than ", b);
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>10 is less than 20</pre>
<pre>10 is less than 20</pre>


=={{header|Dc}}==
=={{header|Dc}}==
<lang dc>[Use _ (underscore) as negative sign for numbers.]P []pP
<syntaxhighlight lang="dc">[Use _ (underscore) as negative sign for numbers.]P []pP
[Enter two numbers to compare: ]P
[Enter two numbers to compare: ]P
? sbsa
? sbsa
Line 1,225: Line 1,225:
[ [equal to]]sp lb la =p
[ [equal to]]sp lb la =p
la n [ is ]P P [ ]P lbn []pP
la n [ is ]P P [ ]P lbn []pP
</syntaxhighlight>
</lang>
{{out}}
{{out}}
44 is greater than 3
44 is greater than 3


=={{header|DCL}}==
=={{header|DCL}}==
<lang DCL>$ inquire a "Please provide an integer"
<syntaxhighlight lang="dcl">$ inquire a "Please provide an integer"
$ inquire b "Please provide another"
$ inquire b "Please provide another"
$ if a .lt. b then $ write sys$output "the first integer is less"
$ if a .lt. b then $ write sys$output "the first integer is less"
$ if a .eq. b then $ write sys$output "the integers have the same value"
$ if a .eq. b then $ write sys$output "the integers have the same value"
$ if a .gt. b then $ write sys$output "the first integer is greater"</lang>
$ if a .gt. b then $ write sys$output "the first integer is greater"</syntaxhighlight>
{{out}}
{{out}}
<pre>$ @integer_comparison
<pre>$ @integer_comparison
Line 1,252: Line 1,252:
:''Slightly different than the [[#Pascal|Pascal]] example''
:''Slightly different than the [[#Pascal|Pascal]] example''


<lang Delphi>program IntegerCompare;
<syntaxhighlight lang="delphi">program IntegerCompare;


{$APPTYPE CONSOLE}
{$APPTYPE CONSOLE}
Line 1,263: Line 1,263:
if a = b then Writeln(a, ' is equal to ', b);
if a = b then Writeln(a, ' is equal to ', b);
if a > b then Writeln(a, ' is greater than ', b);
if a > b then Writeln(a, ' is greater than ', b);
end.</lang>
end.</syntaxhighlight>


=={{header|Draco}}==
=={{header|Draco}}==
<lang draco>proc nonrec main() void:
<syntaxhighlight lang="draco">proc nonrec main() void:
int a, b;
int a, b;
write("Please enter two integers: ");
write("Please enter two integers: ");
Line 1,274: Line 1,274:
elif a>b then writeln(a, " > ", b)
elif a>b then writeln(a, " > ", b)
fi
fi
corp</lang>
corp</syntaxhighlight>


=={{header|Dyalect}}==
=={{header|Dyalect}}==
Line 1,280: Line 1,280:
{{trans|Clipper}}
{{trans|Clipper}}


<lang Dyalect>func compare(a, b) {
<syntaxhighlight lang="dyalect">func compare(a, b) {
if a < b {
if a < b {
"A is less than B"
"A is less than B"
Line 1,288: Line 1,288:
"A equals B"
"A equals B"
}
}
}</lang>
}</syntaxhighlight>


=={{header|E}}==
=={{header|E}}==
<lang e>def compare(a :int, b :int) {
<syntaxhighlight lang="e">def compare(a :int, b :int) {
println(if (a < b) { `$a < $b` } \
println(if (a < b) { `$a < $b` } \
else if (a <=> b) { `$a = $b` } \
else if (a <=> b) { `$a = $b` } \
else if (a > b) { `$a > $b` } \
else if (a > b) { `$a > $b` } \
else { `You're calling that an integer?` })
else { `You're calling that an integer?` })
}</lang>
}</syntaxhighlight>


=={{header|EasyLang}}==
=={{header|EasyLang}}==
<lang>a = number input
<syntaxhighlight lang="text">a = number input
b = number input
b = number input
if a < b
if a < b
Line 1,309: Line 1,309:
if a > b
if a > b
print "greater"
print "greater"
.</lang>
.</syntaxhighlight>


=={{header|ECL}}==
=={{header|ECL}}==
<syntaxhighlight lang="ecl">
<lang ECL>
CompareThem(INTEGER A,INTEGER B) := FUNCTION
CompareThem(INTEGER A,INTEGER B) := FUNCTION
Result := A <=> B;
Result := A <=> B;
Line 1,322: Line 1,322:
CompareThem(2,2); //Shows "2 is equal to 2"
CompareThem(2,2); //Shows "2 is equal to 2"
CompareThem(2,1); //Shows "2 is greater than 1"
CompareThem(2,1); //Shows "2 is greater than 1"
</syntaxhighlight>
</lang>


=={{header|EDSAC order code}}==
=={{header|EDSAC order code}}==
The EDSAC offers two conditional branching orders, <tt>E</tt> (branch if the accumulator >= 0) and <tt>G</tt> (branch if the accumulator < 0). Testing for equality thus requires two operations.
The EDSAC offers two conditional branching orders, <tt>E</tt> (branch if the accumulator >= 0) and <tt>G</tt> (branch if the accumulator < 0). Testing for equality thus requires two operations.
<lang edsac>[ Integer comparison
<syntaxhighlight lang="edsac">[ Integer comparison
==================
==================
Line 1,380: Line 1,380:
[ 18 ] AF [ - character ]
[ 18 ] AF [ - character ]
EZPF [ begin execution ]</lang>
EZPF [ begin execution ]</syntaxhighlight>


=={{header|Efene}}==
=={{header|Efene}}==
Line 1,386: Line 1,386:
since if does pattern matching the else is required to avoid the application from crashing
since if does pattern matching the else is required to avoid the application from crashing


<lang efene>compare = fn (A, B) {
<syntaxhighlight lang="efene">compare = fn (A, B) {
if A == B {
if A == B {
io.format("~p equals ~p~n", [A, B])
io.format("~p equals ~p~n", [A, B])
Line 1,415: Line 1,415:
compare(4, 5)
compare(4, 5)
}
}
</syntaxhighlight>
</lang>


=={{header|Eiffel}}==
=={{header|Eiffel}}==
<lang Eiffel>class
<syntaxhighlight lang="eiffel">class
APPLICATION
APPLICATION
inherit
inherit
Line 1,447: Line 1,447:
end
end
end
end
end</lang>
end</syntaxhighlight>


=={{header|Elena}}==
=={{header|Elena}}==
ELENA 4.x:
ELENA 4.x:
<lang elena>import extensions;
<syntaxhighlight lang="elena">import extensions;
public program()
public program()
Line 1,466: Line 1,466:
if (a > b)
if (a > b)
{ console.printLine(a," is greater than ",b) }
{ console.printLine(a," is greater than ",b) }
}</lang>
}</syntaxhighlight>


=={{header|Elixir}}==
=={{header|Elixir}}==
<lang ELixir>{a,_} = IO.gets("Enter your first integer: ") |> Integer.parse
<syntaxhighlight lang="elixir">{a,_} = IO.gets("Enter your first integer: ") |> Integer.parse
{b,_} = IO.gets("Enter your second integer: ") |> Integer.parse
{b,_} = IO.gets("Enter your second integer: ") |> Integer.parse


Line 1,479: Line 1,479:
a == b ->
a == b ->
IO.puts "#{a} is equal to #{b}"
IO.puts "#{a} is equal to #{b}"
end</lang>
end</syntaxhighlight>


=={{header|Emacs Lisp}}==
=={{header|Emacs Lisp}}==


<lang Lisp>(defun integer-comparison (a b)
<syntaxhighlight lang="lisp">(defun integer-comparison (a b)
"Compare A to B and print the outcome in the message buffer."
"Compare A to B and print the outcome in the message buffer."
(interactive "nFirst integer ⇒\nnSecond integer ⇒")
(interactive "nFirst integer ⇒\nnSecond integer ⇒")
Line 1,489: Line 1,489:
((< a b) (message "%d is less than %d." a b))
((< a b) (message "%d is less than %d." a b))
((> a b) (message "%d is greater than %d." a b))
((> a b) (message "%d is greater than %d." a b))
((= a b) (message "%d is equal to %d." a b))))</lang>
((= a b) (message "%d is equal to %d." a b))))</syntaxhighlight>


Invoke from within Emacs Lisp (or e.g., with <code>M-:</code>) as <code>(integer-comparison 12 42)</code>
Invoke from within Emacs Lisp (or e.g., with <code>M-:</code>) as <code>(integer-comparison 12 42)</code>
Line 1,495: Line 1,495:


=={{header|Erlang}}==
=={{header|Erlang}}==
<lang erlang>
<syntaxhighlight lang="erlang">
main() ->
main() ->
{ok, [N]} = io:fread("First integer: ", "~d"),
{ok, [N]} = io:fread("First integer: ", "~d"),
Line 1,514: Line 1,514:
end.
end.


</syntaxhighlight>
</lang>


=={{header|Euphoria}}==
=={{header|Euphoria}}==
<lang Euphoria>include get.e
<syntaxhighlight lang="euphoria">include get.e


integer a,b
integer a,b
Line 1,531: Line 1,531:
puts(1,"grater then")
puts(1,"grater then")
end if
end if
puts(1," b")</lang>
puts(1," b")</syntaxhighlight>


=={{header|Excel}}==
=={{header|Excel}}==
Line 1,537: Line 1,537:
Let's say you type in the values in cells A1 and B1, in C1, type in the following in a MS Excel 2010 sheet:
Let's say you type in the values in cells A1 and B1, in C1, type in the following in a MS Excel 2010 sheet:


<lang excel>
<syntaxhighlight lang="excel">
=IF($A1>$B1;concatenate($A1;" is greater than ";$B1);IF($A1<$B1;concatenate($A1;" is smaller than ";$B1);concatenate($A1;" is equal to ";$B1)))
=IF($A1>$B1;concatenate($A1;" is greater than ";$B1);IF($A1<$B1;concatenate($A1;" is smaller than ";$B1);concatenate($A1;" is equal to ";$B1)))
</syntaxhighlight>
</lang>


In a Google Docs spreadsheet, that becomes :
In a Google Docs spreadsheet, that becomes :


<lang excel>
<syntaxhighlight lang="excel">
=IF($A1>$B1,concatenate($A1," is greater than ",$B1),IF($A1<$B1,concatenate($A1," is smaller than ",$B1),concatenate($A1," is equal to ",$B1)))
=IF($A1>$B1,concatenate($A1," is greater than ",$B1),IF($A1<$B1,concatenate($A1," is smaller than ",$B1),concatenate($A1," is equal to ",$B1)))
</syntaxhighlight>
</lang>


=={{header|F_Sharp|F#}}==
=={{header|F_Sharp|F#}}==
<lang fsharp>let compare_ints a b =
<syntaxhighlight lang="fsharp">let compare_ints a b =
let r =
let r =
match a with
match a with
Line 1,555: Line 1,555:
| x when x > b -> 1, printfn "%d is greater than %d" x b
| x when x > b -> 1, printfn "%d is greater than %d" x b
| x -> 0, printf "default condition (not reached)"
| x -> 0, printf "default condition (not reached)"
fst r</lang>
fst r</syntaxhighlight>


=={{header|Factor}}==
=={{header|Factor}}==
<lang factor>: example ( -- )
<syntaxhighlight lang="factor">: example ( -- )
readln readln [ string>number ] bi@
readln readln [ string>number ] bi@
[ > [ "A > B" print ] when ]
[ > [ "A > B" print ] when ]
[ < [ "A < B" print ] when ]
[ < [ "A < B" print ] when ]
[ = [ "A = B" print ] when ] 2tri ;
[ = [ "A = B" print ] when ] 2tri ;
</syntaxhighlight>
</lang>


=={{header|FALSE}}==
=={{header|FALSE}}==
Only equals and greater than are available.
Only equals and greater than are available.
<lang false>^^ \$@$@$@$@\
<syntaxhighlight lang="false">^^ \$@$@$@$@\
>[\$," is greater than "\$,]?
>[\$," is greater than "\$,]?
\>[\$," is less than "\$,]?
\>[\$," is less than "\$,]?
=["characters are equal"]?</lang>
=["characters are equal"]?</syntaxhighlight>


=={{header|Fantom}}==
=={{header|Fantom}}==
Line 1,576: Line 1,576:
Uses Env.cur to access stdin and stdout.
Uses Env.cur to access stdin and stdout.


<lang fantom>class Main
<syntaxhighlight lang="fantom">class Main
{
{
public static Void main ()
public static Void main ()
Line 1,598: Line 1,598:
}
}
}
}
</syntaxhighlight>
</lang>


=={{header|Fermat}}==
=={{header|Fermat}}==
<syntaxhighlight lang=fermat>Func Compare =
<syntaxhighlight lang="fermat">Func Compare =
?a;
?a;
?b;
?b;
Line 1,611: Line 1,611:
=={{header|Fish}}==
=={{header|Fish}}==
This example assumes you [http://www.esolangs.org/wiki/Fish#Input.2Foutput pre-populate] the stack with the two integers.
This example assumes you [http://www.esolangs.org/wiki/Fish#Input.2Foutput pre-populate] the stack with the two integers.
<lang Fish>l2=?vv ~< v o<
<syntaxhighlight lang="fish">l2=?vv ~< v o<
v <>l?^"Please pre-populate the stack with the two integers."ar>l?^;
v <>l?^"Please pre-populate the stack with the two integers."ar>l?^;
\$:@@:@)?v v ;oanv!!!?<
\$:@@:@)?v v ;oanv!!!?<
Line 1,623: Line 1,623:
> v
> v
/oo". "nooooo" and "n$< v o<
/oo". "nooooo" and "n$< v o<
>"They're not equal, not greater than and not smaller than eachother... strange."ar>l?^;</lang>
>"They're not equal, not greater than and not smaller than eachother... strange."ar>l?^;</syntaxhighlight>


The last three lines aren't really needed, because it will never become true :P but I included them to show a way to do some error checking.
The last three lines aren't really needed, because it will never become true :P but I included them to show a way to do some error checking.
Line 1,630: Line 1,630:


To keep the example simple, the word takes the two numbers from the stack.
To keep the example simple, the word takes the two numbers from the stack.
<lang forth>: compare-integers ( a b -- )
<syntaxhighlight lang="forth">: compare-integers ( a b -- )
2dup < if ." a is less than b" then
2dup < if ." a is less than b" then
2dup > if ." a is greater than b" then
2dup > if ." a is greater than b" then
= if ." a is equal to b" then ;</lang>
= if ." a is equal to b" then ;</syntaxhighlight>


=={{header|Fortran}}==
=={{header|Fortran}}==
In ALL Fortran versions (including original 1950's era) you could use an "arithmetic IF" statement to compare using subtraction:
In ALL Fortran versions (including original 1950's era) you could use an "arithmetic IF" statement to compare using subtraction:
<lang fortran>program arithif
<syntaxhighlight lang="fortran">program arithif
integer a, b
integer a, b


Line 1,653: Line 1,653:
40 continue
40 continue


end</lang>
end</syntaxhighlight>


In ANSI FORTRAN 66 or later you could use relational operators (.lt., .gt., .eq., etc.) and unstructured IF statements:
In ANSI FORTRAN 66 or later you could use relational operators (.lt., .gt., .eq., etc.) and unstructured IF statements:
<lang fortran>program compare
<syntaxhighlight lang="fortran">program compare
integer a, b
integer a, b
c fortran 77 I/O statements, for simplicity
c fortran 77 I/O statements, for simplicity
Line 1,664: Line 1,664:
if (a .eq. b) write(*, *) a, ' is equal to ', b
if (a .eq. b) write(*, *) a, ' is equal to ', b
if (a .gt. b) write(*, *) a, ' is greater than ', b
if (a .gt. b) write(*, *) a, ' is greater than ', b
end</lang>
end</syntaxhighlight>


In ANSI FORTRAN 77 or later you can use relational operators and structured IF statements:
In ANSI FORTRAN 77 or later you can use relational operators and structured IF statements:
<lang fortran>program compare
<syntaxhighlight lang="fortran">program compare
integer a, b
integer a, b
read(*,*) a, b
read(*,*) a, b
Line 1,679: Line 1,679:
end if
end if


end</lang>
end</syntaxhighlight>


In ISO Fortran 90 or later you can use symbolic relational operators (<, >, ==, etc.)
In ISO Fortran 90 or later you can use symbolic relational operators (<, >, ==, etc.)
<lang fortran>program compare
<syntaxhighlight lang="fortran">program compare
integer :: a, b
integer :: a, b
read(*,*) a, b
read(*,*) a, b
Line 1,694: Line 1,694:
end if
end if


end program compare</lang>
end program compare</syntaxhighlight>


=={{header|FreeBASIC}}==
=={{header|FreeBASIC}}==
<lang freebasic>' FB 1.05.0 Win64
<syntaxhighlight lang="freebasic">' FB 1.05.0 Win64


Dim As Integer x, y
Dim As Integer x, y
Line 1,716: Line 1,716:
Print
Print
Print "Press any key to exit"
Print "Press any key to exit"
Sleep</lang>
Sleep</syntaxhighlight>


=={{header|friendly interactive shell}}==
=={{header|friendly interactive shell}}==
<lang fishshell>read a
<syntaxhighlight lang="fishshell">read a
read b
read b


Line 1,728: Line 1,728:
else if test $a -eq $b
else if test $a -eq $b
echo Equal
echo Equal
end</lang>
end</syntaxhighlight>


=={{header|Frink}}==
=={{header|Frink}}==
All integers in Frink can be arbitrarily large.
All integers in Frink can be arbitrarily large.


<lang frink>[a,b] = eval[input["Enter numbers",["a","b"]]]
<syntaxhighlight lang="frink">[a,b] = eval[input["Enter numbers",["a","b"]]]
if a<b
if a<b
println["$a < $b"]
println["$a < $b"]
Line 1,739: Line 1,739:
println["$a == $b"]
println["$a == $b"]
if a>b
if a>b
println["$a > $b"]</lang>
println["$a > $b"]</syntaxhighlight>


=={{header|FunL}}==
=={{header|FunL}}==
<lang funl>import console.readInt
<syntaxhighlight lang="funl">import console.readInt


a = readInt()
a = readInt()
Line 1,749: Line 1,749:
val (_, c) = [((<), 'less than'), ((==), 'equal to'), ((>), 'greater than')].find( (compare, _) -> compare(a, b) ).get()
val (_, c) = [((<), 'less than'), ((==), 'equal to'), ((>), 'greater than')].find( (compare, _) -> compare(a, b) ).get()


println( "$a is $c $b." )</lang>
println( "$a is $c $b." )</syntaxhighlight>


=={{header|FutureBasic}}==
=={{header|FutureBasic}}==
Note: Strictly speaking, it's preferable to use "==" when comparing integers as seen in this example. While the "=" sign will work as a comparison in most cases, technically it should be used for assignment, i.e. a = 3 when a is assigned the value of 3, as contrasted with a == 3, where the value of a is being compared with 3. FB will flag a warning when "==" is used to compare two single, doubles or floats since comparing real numbers can be inaccurate.
Note: Strictly speaking, it's preferable to use "==" when comparing integers as seen in this example. While the "=" sign will work as a comparison in most cases, technically it should be used for assignment, i.e. a = 3 when a is assigned the value of 3, as contrasted with a == 3, where the value of a is being compared with 3. FB will flag a warning when "==" is used to compare two single, doubles or floats since comparing real numbers can be inaccurate.
<lang futurebasic>_window = 1
<syntaxhighlight lang="futurebasic">_window = 1
begin enum 1
begin enum 1
_integer1Fld
_integer1Fld
Line 1,801: Line 1,801:
on dialog fn DoDialog
on dialog fn DoDialog


HandleEvents</lang>
HandleEvents</syntaxhighlight>


=={{header|Fōrmulæ}}==
=={{header|Fōrmulæ}}==
Line 1,812: Line 1,812:


=={{header|Gambas}}==
=={{header|Gambas}}==
<lang gambas>Public Sub Form_Open()
<syntaxhighlight lang="gambas">Public Sub Form_Open()
Dim sIn As String = InputBox("Enter 2 integers seperated by a comma")
Dim sIn As String = InputBox("Enter 2 integers seperated by a comma")
Dim iFirst, iSecond As Integer
Dim iFirst, iSecond As Integer
Line 1,823: Line 1,823:
If iFirst = iSecond Then Print iFirst & " is equal to " & iSecond
If iFirst = iSecond Then Print iFirst & " is equal to " & iSecond


End</lang>
End</syntaxhighlight>
Output:
Output:
<pre>
<pre>
Line 1,830: Line 1,830:


=={{header|Go}}==
=={{header|Go}}==
<lang go>package main
<syntaxhighlight lang="go">package main


import (
import (
Line 1,855: Line 1,855:
fmt.Println(n1, "greater than", n2)
fmt.Println(n1, "greater than", n2)
}
}
}</lang>
}</syntaxhighlight>


=={{header|Groovy}}==
=={{header|Groovy}}==


===Relational Operators===
===Relational Operators===
<lang groovy>def comparison = { a, b ->
<syntaxhighlight lang="groovy">def comparison = { a, b ->
println "a ? b = ${a} ? ${b} = a ${a < b ? '<' : a > b ? '>' : a == b ? '==' : '?'} b"
println "a ? b = ${a} ? ${b} = a ${a < b ? '<' : a > b ? '>' : a == b ? '==' : '?'} b"
}</lang>
}</syntaxhighlight>


Program:
Program:
<lang groovy>comparison(2000,3)
<syntaxhighlight lang="groovy">comparison(2000,3)
comparison(2000,300000)
comparison(2000,300000)
comparison(2000,2000)</lang>
comparison(2000,2000)</syntaxhighlight>


{{out}}
{{out}}
Line 1,876: Line 1,876:
==="Spaceship" (compareTo) Operator===
==="Spaceship" (compareTo) Operator===
Using spaceship operator and a lookup table:
Using spaceship operator and a lookup table:
<lang groovy>final rels = [ (-1) : '<', 0 : '==', 1 : '>' ].asImmutable()
<syntaxhighlight lang="groovy">final rels = [ (-1) : '<', 0 : '==', 1 : '>' ].asImmutable()
def comparisonSpaceship = { a, b ->
def comparisonSpaceship = { a, b ->
println "a ? b = ${a} ? ${b} = a ${rels[a <=> b]} b"
println "a ? b = ${a} ? ${b} = a ${rels[a <=> b]} b"
}</lang>
}</syntaxhighlight>


Program:
Program:
<lang groovy>comparison(2000,3)
<syntaxhighlight lang="groovy">comparison(2000,3)
comparison(2000,300000)
comparison(2000,300000)
comparison(2000,2000)</lang>
comparison(2000,2000)</syntaxhighlight>


{{out}}
{{out}}
Line 1,892: Line 1,892:


=={{header|Harbour}}==
=={{header|Harbour}}==
<lang visualfoxpro>PROCEDURE Compare( a, b )
<syntaxhighlight lang="visualfoxpro">PROCEDURE Compare( a, b )


IF a < b
IF a < b
Line 1,902: Line 1,902:
ENDIF
ENDIF


RETURN</lang>
RETURN</syntaxhighlight>


=={{header|Haskell}}==
=={{header|Haskell}}==
<lang haskell>myCompare :: Integer -> Integer -> String
<syntaxhighlight lang="haskell">myCompare :: Integer -> Integer -> String
myCompare a b
myCompare a b
| a < b = "A is less than B"
| a < b = "A is less than B"
Line 1,914: Line 1,914:
a <- readLn
a <- readLn
b <- readLn
b <- readLn
putStrLn $ myCompare a b</lang>
putStrLn $ myCompare a b</syntaxhighlight>
However, the more idiomatic and less error-prone way to do it in Haskell would be to use a compare function that returns type Ordering, which is either LT, GT, or EQ:
However, the more idiomatic and less error-prone way to do it in Haskell would be to use a compare function that returns type Ordering, which is either LT, GT, or EQ:
<lang haskell>myCompare a b = case compare a b of
<syntaxhighlight lang="haskell">myCompare a b = case compare a b of
LT -> "A is less than B"
LT -> "A is less than B"
GT -> "A is greater than B"
GT -> "A is greater than B"
EQ -> "A equals B"</lang>
EQ -> "A equals B"</syntaxhighlight>


=={{header|hexiscript}}==
=={{header|hexiscript}}==
<lang hexiscript>let a scan int
<syntaxhighlight lang="hexiscript">let a scan int
let b scan int
let b scan int


Line 1,935: Line 1,935:
if a = b
if a = b
println a + " is equal to " + b
println a + " is equal to " + b
endif</lang>
endif</syntaxhighlight>


=={{header|HicEst}}==
=={{header|HicEst}}==
<lang hicest>DLG(NameEdit=a, NameEdit=b, Button='OK')
<syntaxhighlight lang="hicest">DLG(NameEdit=a, NameEdit=b, Button='OK')
IF (a < b) THEN
IF (a < b) THEN
Line 1,946: Line 1,946:
ELSEIF(a > b) THEN
ELSEIF(a > b) THEN
WRITE(Messagebox) a, ' is greater than ', b
WRITE(Messagebox) a, ' is greater than ', b
ENDIF</lang>
ENDIF</syntaxhighlight>


=={{header|HolyC}}==
=={{header|HolyC}}==
<lang holyc>I64 *a, *b;
<syntaxhighlight lang="holyc">I64 *a, *b;
a = Str2I64(GetStr("Enter your first number: "));
a = Str2I64(GetStr("Enter your first number: "));
b = Str2I64(GetStr("Enter your second number: "));
b = Str2I64(GetStr("Enter your second number: "));
Line 1,960: Line 1,960:


if (a > b)
if (a > b)
Print("%d is greater than %d\n", a, b);</lang>
Print("%d is greater than %d\n", a, b);</syntaxhighlight>


=={{header|Hy}}==
=={{header|Hy}}==
<lang clojure>(def a (int (input "Enter value of a: ")))
<syntaxhighlight lang="clojure">(def a (int (input "Enter value of a: ")))
(def b (int (input "Enter value of b: ")))
(def b (int (input "Enter value of b: ")))


(print (cond [(< a b) "a is less than b"]
(print (cond [(< a b) "a is less than b"]
[(> a b) "a is greater than b"]
[(> a b) "a is greater than b"]
[(= a b) "a is equal to b"]))</lang>
[(= a b) "a is equal to b"]))</syntaxhighlight>


=={{header|i}}==
=={{header|i}}==
<lang i>software {
<syntaxhighlight lang="i">software {
a = number(read(' '))
a = number(read(' '))
b = number(read())
b = number(read())
Line 1,986: Line 1,986:
print(a, " is greater than ", b)
print(a, " is greater than ", b)
end
end
}</lang>
}</syntaxhighlight>


=={{header|Icon}} and {{header|Unicon}}==
=={{header|Icon}} and {{header|Unicon}}==
<lang Icon>procedure main()
<syntaxhighlight lang="icon">procedure main()


until integer(a) do {
until integer(a) do {
Line 2,004: Line 2,004:
write(a," = ", a = b)
write(a," = ", a = b)
write(a," > ", a > b)
write(a," > ", a > b)
end</lang>
end</syntaxhighlight>


{{out}}
{{out}}
Line 2,014: Line 2,014:
=={{header|J}}==
=={{header|J}}==
Comparison is accomplished by the verb <code>compare</code>, which provides logical-numeric output.<br>Text elaborating the output of <code>compare</code> is provided by <code>cti</code>:
Comparison is accomplished by the verb <code>compare</code>, which provides logical-numeric output.<br>Text elaborating the output of <code>compare</code> is provided by <code>cti</code>:
<lang j>compare=: < , = , >
<syntaxhighlight lang="j">compare=: < , = , >


cti=: dyad define
cti=: dyad define
Line 2,020: Line 2,020:
English =. ' is less than ';' is equal to ';' is greater than '
English =. ' is less than ';' is equal to ';' is greater than '
x (":@[, (compare select English"_), ":@]) y
x (":@[, (compare select English"_), ":@]) y
)</lang>
)</syntaxhighlight>
Examples of use:
Examples of use:
<lang j> 4 compare 4
<syntaxhighlight lang="j"> 4 compare 4
0 1 0
0 1 0
4 cti 3
4 cti 3
4 is greater than 3</lang>
4 is greater than 3</syntaxhighlight>


=={{header|Java}}==
=={{header|Java}}==
<lang java>import java.io.*;
<syntaxhighlight lang="java">import java.io.*;


public class compInt {
public class compInt {
Line 2,048: Line 2,048:
} catch(IOException e) { }
} catch(IOException e) { }
}
}
}</lang>
}</syntaxhighlight>


=={{header|JavaScript}}==
=={{header|JavaScript}}==
<lang javascript>
<syntaxhighlight lang="javascript">
// Using type coercion
// Using type coercion
function compare(a, b) {
function compare(a, b) {
Line 2,078: Line 2,078:
}
}
}
}
</syntaxhighlight>
</lang>


=={{header|Joy}}==
=={{header|Joy}}==
<syntaxhighlight lang=Joy>#!/usr/local/bin/joy.exe
<syntaxhighlight lang="joy">#!/usr/local/bin/joy.exe
DEFINE
DEFINE
prompt == "Please enter a number and <Enter>: " putchars;
prompt == "Please enter a number and <Enter>: " putchars;
Line 2,104: Line 2,104:


=={{header|jq}}==
=={{header|jq}}==
<lang jq># compare/0 compares the first two items if they are numbers,
<syntaxhighlight lang="jq"># compare/0 compares the first two items if they are numbers,
# otherwise an "uncomparable" message is emitted.
# otherwise an "uncomparable" message is emitted.


Line 2,119: Line 2,119:
end ;
end ;


compare</lang>
compare</syntaxhighlight>


Examples;
Examples;
<syntaxhighlight lang="jq">
<lang jq>
$ jq -s -r -f Integer_comparison.jq
$ jq -s -r -f Integer_comparison.jq
1 2
1 2
Line 2,130: Line 2,130:
1 "a"
1 "a"
1 is uncomparable to a
1 is uncomparable to a
</syntaxhighlight>
</lang>


=={{header|Julia}}==
=={{header|Julia}}==
<lang Julia>function compare()
<syntaxhighlight lang="julia">function compare()
int1 = readline(stdin)
int1 = readline(stdin)
int2 = readline(stdin)
int2 = readline(stdin)
Line 2,143: Line 2,143:
int2)
int2)
end
end
</lang>{{out}}
</syntaxhighlight>{{out}}
<pre>julia> compare()
<pre>julia> compare()
3
3
Line 2,151: Line 2,151:


=={{header|Kotlin}}==
=={{header|Kotlin}}==
<lang scala>fun main(args: Array<String>) {
<syntaxhighlight lang="scala">fun main(args: Array<String>) {
val n1 = readLine()!!.toLong()
val n1 = readLine()!!.toLong()
val n2 = readLine()!!.toLong()
val n2 = readLine()!!.toLong()
Line 2,160: Line 2,160:
else -> ""
else -> ""
})
})
}</lang>
}</syntaxhighlight>


=={{header|Lambdatalk}}==
=={{header|Lambdatalk}}==
<syntaxhighlight lang="scheme">
<lang Scheme>
{def compare
{def compare
{lambda {:a :b}
{lambda {:a :b}
Line 2,180: Line 2,180:
{compare 1 1}
{compare 1 1}
-> 1 is equal to 1
-> 1 is equal to 1
</syntaxhighlight>
</lang>


=={{header|Lasso}}==
=={{header|Lasso}}==
<lang Lasso>local(
<syntaxhighlight lang="lasso">local(
number1 = integer(web_request -> param('number1')),
number1 = integer(web_request -> param('number1')),
number2 = integer(web_request -> param('number2'))
number2 = integer(web_request -> param('number2'))
Line 2,192: Line 2,192:
#number1 == #number2 ? 'Number 1 is the same as Number 2' | 'Number 1 is not the same as Number 2'
#number1 == #number2 ? 'Number 1 is the same as Number 2' | 'Number 1 is not the same as Number 2'
'<br />'
'<br />'
#number1 > #number2 ? 'Number 1 is greater than Number 2' | 'Number 1 is not greater than Number 2'</lang>
#number1 > #number2 ? 'Number 1 is greater than Number 2' | 'Number 1 is not greater than Number 2'</syntaxhighlight>


{{out}}
{{out}}
Line 2,202: Line 2,202:
=={{header|Liberty BASIC}}==
=={{header|Liberty BASIC}}==
Verbose version:
Verbose version:
<lang lb>input "Enter an integer for a. ";a
<syntaxhighlight lang="lb">input "Enter an integer for a. ";a
input "Enter an integer for b. ";b
input "Enter an integer for b. ";b


Line 2,221: Line 2,221:
end select
end select
</lang>
</syntaxhighlight>


Concise:
Concise:
<lang lb>input "Enter an integer for a. ";a
<syntaxhighlight lang="lb">input "Enter an integer for a. ";a
input "Enter an integer for b. ";b
input "Enter an integer for b. ";b


Line 2,231: Line 2,231:
if eval("a"+op$+"b") then print "a"+op$+"b " ; a;" ";op$;" ";b
if eval("a"+op$+"b") then print "a"+op$+"b " ; a;" ";op$;" ";b
next
next
</syntaxhighlight>
</lang>


=={{header|LIL}}==
=={{header|LIL}}==
<lang tcl>print "Enter two numbers separated by space"
<syntaxhighlight lang="tcl">print "Enter two numbers separated by space"
set rc [readline]
set rc [readline]
set a [index $rc 0]
set a [index $rc 0]
Line 2,241: Line 2,241:
if {$a < $b} {print "$a is less than $b"}
if {$a < $b} {print "$a is less than $b"}
if {$a == $b} {print "$a is equal to $b"}
if {$a == $b} {print "$a is equal to $b"}
if {$a > $b} {print "$a is greater than $b"}</lang>
if {$a > $b} {print "$a is greater than $b"}</syntaxhighlight>


=={{header|Lingo}}==
=={{header|Lingo}}==
Lingo programs are normally not run in the console, so interactive user input is handled via GUI. To not clutter this page with GUI creation code, here only the comparison part of the task:
Lingo programs are normally not run in the console, so interactive user input is handled via GUI. To not clutter this page with GUI creation code, here only the comparison part of the task:
<lang lingo>on compare (a, b)
<syntaxhighlight lang="lingo">on compare (a, b)
if a < b then put a&" is less than "&b
if a < b then put a&" is less than "&b
if a = b then put a&" is equal to "&b
if a = b then put a&" is equal to "&b
if a > b then put a&" is greater than "&b
if a > b then put a&" is greater than "&b
end</lang>
end</syntaxhighlight>


=={{header|LiveCode}}==
=={{header|LiveCode}}==
<lang LiveCode>ask question "Enter 2 numbers (comma separated)" with empty titled "Enter 2 numbers"
<syntaxhighlight lang="livecode">ask question "Enter 2 numbers (comma separated)" with empty titled "Enter 2 numbers"
if it is not empty then
if it is not empty then
put item 1 of it into num1
put item 1 of it into num1
Line 2,271: Line 2,271:
end switch
end switch
end if
end if
end if</lang>
end if</syntaxhighlight>


=={{header|LLVM}}==
=={{header|LLVM}}==
Line 2,278: Line 2,278:
{{libheader|cstdlib}}
{{libheader|cstdlib}}


<lang llvm>; ModuleID = 'test.o'
<syntaxhighlight lang="llvm">; ModuleID = 'test.o'
;e means little endian
;e means little endian
;p: { pointer size : pointer abi : preferred alignment for pointers }
;p: { pointer size : pointer abi : preferred alignment for pointers }
Line 2,369: Line 2,369:


declare i32 @printf(i8* nocapture, ...) nounwind
declare i32 @printf(i8* nocapture, ...) nounwind
</syntaxhighlight>
</lang>


=={{header|Logo}}==
=={{header|Logo}}==
<lang logo>to compare :a :b
<syntaxhighlight lang="logo">to compare :a :b
if :a = :b [(print :a [equals] :b)]
if :a = :b [(print :a [equals] :b)]
if :a < :b [(print :a [is less than] :b)]
if :a < :b [(print :a [is less than] :b)]
if :a > :b [(print :a [is greater than] :b)]
if :a > :b [(print :a [is greater than] :b)]
end</lang>
end</syntaxhighlight>
Each infix operator has prefix synonyms (equalp, equal?, lessp, less?, greaterp, greater?), where the 'p' stands for "predicate" as in [[Lisp]].
Each infix operator has prefix synonyms (equalp, equal?, lessp, less?, greaterp, greater?), where the 'p' stands for "predicate" as in [[Lisp]].


Line 2,383: Line 2,383:


==={{header|avec SI}}===
==={{header|avec SI}}===
<lang LSE>(* Comparaison de deux entiers en LSE (LSE-2000) *)
<syntaxhighlight lang="lse">(* Comparaison de deux entiers en LSE (LSE-2000) *)
ENTIER A, B
ENTIER A, B
LIRE ['Entrez un premier entier:',U] A
LIRE ['Entrez un premier entier:',U] A
Line 2,395: Line 2,395:
SI A > B ALORS
SI A > B ALORS
AFFICHER [U,' est plus grand que ',U,/] A, B
AFFICHER [U,' est plus grand que ',U,/] A, B
FIN SI</lang>
FIN SI</syntaxhighlight>


==={{header|avec ÉVALUER}}===
==={{header|avec ÉVALUER}}===
<lang LSE>(* Comparaison de deux entiers en LSE (LSE-2000) *)
<syntaxhighlight lang="lse">(* Comparaison de deux entiers en LSE (LSE-2000) *)
ENTIER A, B
ENTIER A, B
LIRE ['Entrez un premier entier:',U] A
LIRE ['Entrez un premier entier:',U] A
Line 2,409: Line 2,409:
QUAND AUTRE
QUAND AUTRE
AFFICHER [U,' est plus grand que ',U,/] A, B
AFFICHER [U,' est plus grand que ',U,/] A, B
FIN EVALUER</lang>
FIN EVALUER</syntaxhighlight>


==={{header|avec SI..IS}}===
==={{header|avec SI..IS}}===
<lang LSE>(* Comparaison de deux entiers en LSE (LSE-2000) *)
<syntaxhighlight lang="lse">(* Comparaison de deux entiers en LSE (LSE-2000) *)
ENTIER A, B
ENTIER A, B
LIRE ['Entrez un premier entier:',U] A
LIRE ['Entrez un premier entier:',U] A
Line 2,420: Line 2,420:
SI A = B ALORS ' est égale à ' SINON \
SI A = B ALORS ' est égale à ' SINON \
SI A > B ALORS ' est plus grand que ' SINON '?' IS IS IS, B
SI A > B ALORS ' est plus grand que ' SINON '?' IS IS IS, B
</syntaxhighlight>
</lang>


=={{header|LSE64}}==
=={{header|LSE64}}==
<lang lse64>over : 2 pick
<syntaxhighlight lang="lse64">over : 2 pick
2dup : over over
2dup : over over


Line 2,430: Line 2,430:
compare : 2dup > then " is more than"
compare : 2dup > then " is more than"


show : compare rot , sp ,t sp , nl</lang>
show : compare rot , sp ,t sp , nl</syntaxhighlight>


=={{header|Lua}}==
=={{header|Lua}}==
<lang lua>print('Enter the first number: ')
<syntaxhighlight lang="lua">print('Enter the first number: ')
a = tonumber(io.stdin:read())
a = tonumber(io.stdin:read())
print('Enter the second number: ')
print('Enter the second number: ')
Line 2,440: Line 2,440:
if a < b then print(a .. " is less than " .. b) end
if a < b then print(a .. " is less than " .. b) end
if a > b then print(a .. " is greater than " .. b) end
if a > b then print(a .. " is greater than " .. b) end
if a == b then print(a .. " is equal to " .. b) end</lang>
if a == b then print(a .. " is equal to " .. b) end</syntaxhighlight>


In lua, a double equals symbol is required to test for equality. A single equals sign is used for assignment, and will cause an error during jit precompilation, if it is used within a boolean expression:
In lua, a double equals symbol is required to test for equality. A single equals sign is used for assignment, and will cause an error during jit precompilation, if it is used within a boolean expression:


<lang lua>-- if a = b then print("This will not work")</lang>
<syntaxhighlight lang="lua">-- if a = b then print("This will not work")</syntaxhighlight>


=={{header|Maple}}==
=={{header|Maple}}==
<lang Maple>CompareNumbers := proc( )
<syntaxhighlight lang="maple">CompareNumbers := proc( )
local a, b;
local a, b;
printf( "Enter a number:> " );
printf( "Enter a number:> " );
Line 2,462: Line 2,462:
end proc:
end proc:


CompareNumbers();</lang>
CompareNumbers();</syntaxhighlight>


=={{header|Mathematica}} / {{header|Wolfram Language}}==
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<lang Mathematica>a=Input["Give me the value for a please!"];
<syntaxhighlight lang="mathematica">a=Input["Give me the value for a please!"];
b=Input["Give me the value for b please!"];
b=Input["Give me the value for b please!"];
If[a==b,Print["a equals b"]]
If[a==b,Print["a equals b"]]
If[a>b,Print["a is bigger than b"]]
If[a>b,Print["a is bigger than b"]]
If[a<b,Print["b is bigger than a"]]</lang>
If[a<b,Print["b is bigger than a"]]</syntaxhighlight>


=={{header|Maxima}}==
=={{header|Maxima}}==
<lang maxima>/* all 6 comparison operators (last is "not equal") */
<syntaxhighlight lang="maxima">/* all 6 comparison operators (last is "not equal") */
block(
block(
[a: read("a?"), b: read("b?")],
[a: read("a?"), b: read("b?")],
Line 2,480: Line 2,480:
if a >= b then print(a, ">=", b),
if a >= b then print(a, ">=", b),
if a = b then print(a, "=", b),
if a = b then print(a, "=", b),
if a # b then print(a, "#", b))$</lang>
if a # b then print(a, "#", b))$</syntaxhighlight>


=={{header|MAXScript}}==
=={{header|MAXScript}}==
<lang maxscript>a = getKBValue prompt:"Enter value of a:"
<syntaxhighlight lang="maxscript">a = getKBValue prompt:"Enter value of a:"
b = getKBValue prompt:"Enter value of b:"
b = getKBValue prompt:"Enter value of b:"
if a < b then print "a is less then b"
if a < b then print "a is less then b"
else if a > b then print "a is greater then b"
else if a > b then print "a is greater then b"
else if a == b then print "a is equal to b"</lang>
else if a == b then print "a is equal to b"</syntaxhighlight>


=={{header|Metafont}}==
=={{header|Metafont}}==
<lang metafont>message "integer 1: ";
<syntaxhighlight lang="metafont">message "integer 1: ";
a1 := scantokens readstring;
a1 := scantokens readstring;
message "integer 2: ";
message "integer 2: ";
Line 2,501: Line 2,501:
message decimal a1 & " is equal to " & decimal a2
message decimal a1 & " is equal to " & decimal a2
fi;
fi;
end</lang>
end</syntaxhighlight>


=={{header|min}}==
=={{header|min}}==
{{works with|min|0.19.3}}
{{works with|min|0.19.3}}
<lang min>"$1 is $2 $3."
<syntaxhighlight lang="min">"$1 is $2 $3."
("Enter an integer" ask) 2 times over over
("Enter an integer" ask) 2 times over over
(
(
Line 2,512: Line 2,512:
((==) ("equal to"))
((==) ("equal to"))
) case
) case
' append prepend % print</lang>
' append prepend % print</syntaxhighlight>


=={{header|MiniScript}}==
=={{header|MiniScript}}==
<lang MiniScript>integer1 = input("Please Input Integer 1:").val
<syntaxhighlight lang="miniscript">integer1 = input("Please Input Integer 1:").val
integer2 = input("Please Input Integer 2:").val
integer2 = input("Please Input Integer 2:").val
if integer1 < integer2 then print integer1 + " is less than " + integer2
if integer1 < integer2 then print integer1 + " is less than " + integer2
if integer1 == integer2 then print integer1 + " is equal to " + integer2
if integer1 == integer2 then print integer1 + " is equal to " + integer2
if integer1 > integer2 then print integer1 + " is greater than " + integer2</lang>
if integer1 > integer2 then print integer1 + " is greater than " + integer2</syntaxhighlight>


=={{header|МК-61/52}}==
=={{header|МК-61/52}}==
<lang>- ЗН С/П</lang>
<syntaxhighlight lang="text">- ЗН С/П</syntaxhighlight>


''Input:'' a ^ b
''Input:'' a ^ b
Line 2,532: Line 2,532:
Note that ML/I only has tests for ''equality'', ''greater-than'', and ''greater-than-or-equal''.
Note that ML/I only has tests for ''equality'', ''greater-than'', and ''greater-than-or-equal''.


<lang ML/I>"" Integer comparison
<syntaxhighlight lang="ml/i">"" Integer comparison
"" assumes macros on input stream 1, terminal on stream 2
"" assumes macros on input stream 1, terminal on stream 2
MCSKIP MT,<>
MCSKIP MT,<>
Line 2,549: Line 2,549:
>
>
MCSET S1=1
MCSET S1=1
~MCSET S10=2</lang>
~MCSET S10=2</syntaxhighlight>


=={{header|MMIX}}==
=={{header|MMIX}}==
Some simple error checking is included.
Some simple error checking is included.
<lang mmix>// main registers
<syntaxhighlight lang="mmix">// main registers
p IS $255 % pointer
p IS $255 % pointer
pp GREG % backup for p
pp GREG % backup for p
Line 2,637: Line 2,637:
LDA p,GT % _ : print 'GT'
LDA p,GT % _ : print 'GT'
2H TRAP 0,Fputs,StdOut % print result
2H TRAP 0,Fputs,StdOut % print result
TRAP 0,Halt,0</lang>
TRAP 0,Halt,0</syntaxhighlight>
Example of use:
Example of use:
<pre>~/MIX/MMIX/Progs> mmix compare2ints 121 122
<pre>~/MIX/MMIX/Progs> mmix compare2ints 121 122
Line 2,658: Line 2,658:


=={{header|Modula-2}}==
=={{header|Modula-2}}==
<lang modula2>MODULE IntCompare;
<syntaxhighlight lang="modula2">MODULE IntCompare;


IMPORT InOut;
IMPORT InOut;
Line 2,679: Line 2,679:
InOut.WriteInt(B, 1);
InOut.WriteInt(B, 1);
InOut.WriteLn
InOut.WriteLn
END IntCompare.</lang>
END IntCompare.</syntaxhighlight>


=={{header|Modula-3}}==
=={{header|Modula-3}}==
<lang modula3>MODULE Main;
<syntaxhighlight lang="modula3">MODULE Main;


FROM IO IMPORT Put, GetInt;
FROM IO IMPORT Put, GetInt;
Line 2,699: Line 2,699:
Put(Int(a) & " is greater than " & Int(b) & "\n");
Put(Int(a) & " is greater than " & Int(b) & "\n");
END;
END;
END Main.</lang>
END Main.</syntaxhighlight>


=={{header|MUMPS}}==
=={{header|MUMPS}}==
<lang>INTCOMP
<syntaxhighlight lang="text">INTCOMP
NEW A,B
NEW A,B
INTCOMPREAD
INTCOMPREAD
Line 2,712: Line 2,712:
IF A>B WRITE !,A," is greater than ",B
IF A>B WRITE !,A," is greater than ",B
KILL A,B
KILL A,B
QUIT</lang>
QUIT</syntaxhighlight>
{{out}}
{{out}}
<pre>USER>d INTCOMP^ROSETTA
<pre>USER>d INTCOMP^ROSETTA
Line 2,731: Line 2,731:


=={{header|Nanoquery}}==
=={{header|Nanoquery}}==
<lang Nanoquery>print "enter first integer: "
<syntaxhighlight lang="nanoquery">print "enter first integer: "
first = int(input())
first = int(input())
print "enter second integer: "
print "enter second integer: "
Line 2,742: Line 2,742:
else if first > second
else if first > second
println first + " is greater than " + second
println first + " is greater than " + second
end</lang>
end</syntaxhighlight>


=={{header|Nemerle}}==
=={{header|Nemerle}}==
Showing both the use of comparison operators and the .Net Int32.CompareTo() method.
Showing both the use of comparison operators and the .Net Int32.CompareTo() method.
<lang Nemerle>using System;
<syntaxhighlight lang="nemerle">using System;
using System.Console;
using System.Console;


Line 2,776: Line 2,776:
}
}
}
}
}</lang>
}</syntaxhighlight>


=={{header|NetRexx}}==
=={{header|NetRexx}}==
<lang NetRexx>/* NetRexx */
<syntaxhighlight lang="netrexx">/* NetRexx */
options replace format comments java crossref symbols nobinary
options replace format comments java crossref symbols nobinary


Line 2,794: Line 2,794:


return
return
</syntaxhighlight>
</lang>


=={{header|NewLISP}}==
=={{header|NewLISP}}==
<syntaxhighlight lang="newlisp">
<lang NewLISP>
(print "Please enter the first number: ")
(print "Please enter the first number: ")
(set 'A (int (read-line)))
(set 'A (int (read-line)))
Line 2,809: Line 2,809:
(true "less than"))
(true "less than"))
" the second.")
" the second.")
</syntaxhighlight>
</lang>


=={{header|Nim}}==
=={{header|Nim}}==
<lang nim>import rdstdin, strutils
<syntaxhighlight lang="nim">import rdstdin, strutils
var a = parseInt(readLineFromStdin "Enter value of a: ")
var a = parseInt(readLineFromStdin "Enter value of a: ")
var b = parseInt(readLineFromStdin "Enter value of b: ")
var b = parseInt(readLineFromStdin "Enter value of b: ")
Line 2,821: Line 2,821:
echo "a is greater than b"
echo "a is greater than b"
elif a == b:
elif a == b:
echo "a is equal to b"</lang>
echo "a is equal to b"</syntaxhighlight>


=={{header|NSIS}}==
=={{header|NSIS}}==
===Pure NSIS (Using [http://nsis.sourceforge.net/Docs/Chapter4.html#4.9.4.13 IntCmp] directly)===
===Pure NSIS (Using [http://nsis.sourceforge.net/Docs/Chapter4.html#4.9.4.13 IntCmp] directly)===
<lang nsis>
<syntaxhighlight lang="nsis">
Function IntergerComparison
Function IntergerComparison
Push $0
Push $0
Line 2,848: Line 2,848:
Pop $0
Pop $0
FunctionEnd
FunctionEnd
</syntaxhighlight>
</lang>
=== Using [http://nsis.sourceforge.net/LogicLib LogicLib] (bundled library) ===
=== Using [http://nsis.sourceforge.net/LogicLib LogicLib] (bundled library) ===
{{libheader|LogicLib}}
{{libheader|LogicLib}}
<lang nsis>
<syntaxhighlight lang="nsis">
Function IntegerComparison
Function IntegerComparison
Push $0
Push $0
Line 2,870: Line 2,870:
Pop $0
Pop $0
FunctionEnd
FunctionEnd
</syntaxhighlight>
</lang>


=={{header|Oberon-2}}==
=={{header|Oberon-2}}==
<lang oberon2>MODULE Compare;
<syntaxhighlight lang="oberon2">MODULE Compare;


IMPORT In, Out;
IMPORT In, Out;
Line 2,898: Line 2,898:
Out.Ln;
Out.Ln;
END;
END;
END Compare.</lang>
END Compare.</syntaxhighlight>


=={{header|Objeck}}==
=={{header|Objeck}}==
<lang objeck>
<syntaxhighlight lang="objeck">
bundle Default {
bundle Default {
class IntCompare {
class IntCompare {
Line 2,922: Line 2,922:
}
}
}
}
</syntaxhighlight>
</lang>


=={{header|OCaml}}==
=={{header|OCaml}}==
<lang ocaml>let my_compare a b =
<syntaxhighlight lang="ocaml">let my_compare a b =
if a < b then "A is less than B"
if a < b then "A is less than B"
else if a > b then "A is greater than B"
else if a > b then "A is greater than B"
Line 2,934: Line 2,934:
let a = read_int ()
let a = read_int ()
and b = read_int () in
and b = read_int () in
print_endline (my_compare a b)</lang>
print_endline (my_compare a b)</syntaxhighlight>


=={{header|Octave}}==
=={{header|Octave}}==
<lang octave>printf("Enter a: ");
<syntaxhighlight lang="octave">printf("Enter a: ");
a = scanf("%d", "C");
a = scanf("%d", "C");
printf("Enter b: ");
printf("Enter b: ");
Line 2,947: Line 2,947:
elseif (a < b)
elseif (a < b)
disp("a less than b");
disp("a less than b");
endif</lang>
endif</syntaxhighlight>


=={{header|Oforth}}==
=={{header|Oforth}}==


<lang Oforth>import: console
<syntaxhighlight lang="oforth">import: console


: cmpInt
: cmpInt
Line 2,960: Line 2,960:
a b < ifTrue: [ System.Out a << " is less than " << b << cr ]
a b < ifTrue: [ System.Out a << " is less than " << b << cr ]
a b == ifTrue: [ System.Out a << " is equal to " << b << cr ]
a b == ifTrue: [ System.Out a << " is equal to " << b << cr ]
a b > ifTrue: [ System.Out a << " is greater than " << b << cr ] ;</lang>
a b > ifTrue: [ System.Out a << " is greater than " << b << cr ] ;</syntaxhighlight>


=={{header|Ol}}==
=={{header|Ol}}==
<lang scheme>
<syntaxhighlight lang="scheme">
(define (compare a b)
(define (compare a b)
(cond ((< a b) "A is less than B")
(cond ((< a b) "A is less than B")
Line 2,980: Line 2,980:
; manual user input:
; manual user input:
(print (compare (read) (read)))
(print (compare (read) (read)))
</syntaxhighlight>
</lang>


=={{header|Oz}}==
=={{header|Oz}}==
<lang oz>functor
<syntaxhighlight lang="oz">functor
import
import
Application(exit)
Application(exit)
Line 3,010: Line 3,010:


{Application.exit 0}
{Application.exit 0}
end</lang>
end</syntaxhighlight>


=={{header|PARI/GP}}==
=={{header|PARI/GP}}==
<lang parigp>a=input();
<syntaxhighlight lang="parigp">a=input();
b=input();
b=input();
if(a<b, print(a" < "b));
if(a<b, print(a" < "b));
if(a==b, print(a" = "b));
if(a==b, print(a" = "b));
if(a>b, print(a" > "b));</lang>
if(a>b, print(a" > "b));</syntaxhighlight>


=={{header|Pascal}}==
=={{header|Pascal}}==
<lang pascal>program compare(input, output);
<syntaxhighlight lang="pascal">program compare(input, output);


var
var
Line 3,033: Line 3,033:
if (a = b) then writeln(a, ' is equal to ', b);
if (a = b) then writeln(a, ' is equal to ', b);
if (a > b) then writeln(a, ' is greater than ', b);
if (a > b) then writeln(a, ' is greater than ', b);
end.</lang>
end.</syntaxhighlight>


=={{header|Perl}}==
=={{header|Perl}}==
Line 3,040: Line 3,040:
Separate tests for less than, greater than, and equals
Separate tests for less than, greater than, and equals


<lang perl>sub test_num {
<syntaxhighlight lang="perl">sub test_num {
my $f = shift;
my $f = shift;
my $s = shift;
my $s = shift;
Line 3,052: Line 3,052:
return 0; # returns 0 $f is equal to $s
return 0; # returns 0 $f is equal to $s
};
};
};</lang>
};</syntaxhighlight>


All three tests in one. If $f is less than $s return -1, greater than return 1, equal to return 0
All three tests in one. If $f is less than $s return -1, greater than return 1, equal to return 0


<lang perl>sub test_num {
<syntaxhighlight lang="perl">sub test_num {
return $_[0] <=> $_[1];
return $_[0] <=> $_[1];
};</lang>
};</syntaxhighlight>
Note: In Perl, $a and $b are (kind of) reserved identifiers for the built-in ''sort'' function. It's good style to use more meaningful names, anyway.
Note: In Perl, $a and $b are (kind of) reserved identifiers for the built-in ''sort'' function. It's good style to use more meaningful names, anyway.


<lang perl># Get input, test and display
<syntaxhighlight lang="perl"># Get input, test and display
print "Enter two integers: ";
print "Enter two integers: ";
($x, $y) = split ' ', <>;
($x, $y) = split ' ', <>;
print $x, (" is less than ", " is equal to ",
print $x, (" is less than ", " is equal to ",
" is greater than ")[test_num($x, $y) + 1], $y, "\n";</lang>
" is greater than ")[test_num($x, $y) + 1], $y, "\n";</syntaxhighlight>


=={{header|Phix}}==
=={{header|Phix}}==
{{libheader|Phix/basics}}
{{libheader|Phix/basics}}
<!--<lang Phix>-->
<!--<syntaxhighlight lang="phix">-->
<span style="color: #004080;">atom</span> <span style="color: #000000;">a</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">prompt_number</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"first number:"</span><span style="color: #0000FF;">,{}),</span>
<span style="color: #004080;">atom</span> <span style="color: #000000;">a</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">prompt_number</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"first number:"</span><span style="color: #0000FF;">,{}),</span>
<span style="color: #000000;">b</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">prompt_number</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"second number:"</span><span style="color: #0000FF;">,{})</span>
<span style="color: #000000;">b</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">prompt_number</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"second number:"</span><span style="color: #0000FF;">,{})</span>
Line 3,082: Line 3,082:
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">" %g"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">b</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">" %g"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">b</span><span style="color: #0000FF;">)</span>
<!--</lang>-->
<!--</syntaxhighlight>-->


=={{header|PHL}}==
=={{header|PHL}}==


<lang phl>module intergertest;
<syntaxhighlight lang="phl">module intergertest;


extern printf;
extern printf;
Line 3,106: Line 3,106:
return 0;
return 0;
]</lang>
]</syntaxhighlight>


=={{header|PHP}}==
=={{header|PHP}}==
<lang php><?php
<syntaxhighlight lang="php"><?php


echo "Enter an integer [int1]: ";
echo "Enter an integer [int1]: ";
Line 3,135: Line 3,135:
echo "int1 > int2\n";
echo "int1 > int2\n";


?></lang>
?></syntaxhighlight>
Note that this works from the command-line interface only, whereas [http://www.php.net PHP] is usually executed as [[wp:Common_Gateway_Interface CGI]].
Note that this works from the command-line interface only, whereas [http://www.php.net PHP] is usually executed as [[wp:Common_Gateway_Interface CGI]].


=={{header|PicoLisp}}==
=={{header|PicoLisp}}==
<lang PicoLisp>(prin "Please enter two values: ")
<syntaxhighlight lang="picolisp">(prin "Please enter two values: ")


(in NIL # Read from standard input
(in NIL # Read from standard input
Line 3,149: Line 3,149:
((= A B) "equal to")
((= A B) "equal to")
(T "less than") )
(T "less than") )
" the second." ) ) )</lang>
" the second." ) ) )</syntaxhighlight>
{{out}}
{{out}}
<pre>Please enter two values: 4 3
<pre>Please enter two values: 4 3
Line 3,155: Line 3,155:


=={{header|Pike}}==
=={{header|Pike}}==
<lang pike>int main(int argc, array(int) argv){
<syntaxhighlight lang="pike">int main(int argc, array(int) argv){
if(argc != 3){
if(argc != 3){
write("usage: `pike compare-two-ints.pike <x> <y>` where x and y are integers.\n");
write("usage: `pike compare-two-ints.pike <x> <y>` where x and y are integers.\n");
Line 3,171: Line 3,171:
write(a + " is equal to " + b + "\n");
write(a + " is equal to " + b + "\n");
}
}
}</lang>
}</syntaxhighlight>


=={{header|PL/I}}==
=={{header|PL/I}}==
<syntaxhighlight lang="pl/i">
<lang PL/I>
declare (a, b) fixed binary;
declare (a, b) fixed binary;


Line 3,184: Line 3,184:
if a < b then
if a < b then
put skip list ('The second number is greater than the first');
put skip list ('The second number is greater than the first');
</syntaxhighlight>
</lang>


=={{header|Plain English}}==
=={{header|Plain English}}==
<lang plainenglish>To run:
<syntaxhighlight lang="plainenglish">To run:
Start up.
Start up.
Write "Enter the first number: " to the console without advancing.
Write "Enter the first number: " to the console without advancing.
Line 3,197: Line 3,197:
If the first number is greater than the second number, write "Greater than!" to the console.
If the first number is greater than the second number, write "Greater than!" to the console.
Wait for the escape key.
Wait for the escape key.
Shut down.</lang>
Shut down.</syntaxhighlight>


=={{header|Pop11}}==
=={{header|Pop11}}==
<lang pop11>;;; Comparison procedure
<syntaxhighlight lang="pop11">;;; Comparison procedure
define compare_integers(x, y);
define compare_integers(x, y);
if x > y then
if x > y then
Line 3,216: Line 3,216:


;;; Read numbers and call comparison procedure
;;; Read numbers and call comparison procedure
compare_integers(itemrep(), itemrep());</lang>
compare_integers(itemrep(), itemrep());</syntaxhighlight>


=={{header|PowerShell}}==
=={{header|PowerShell}}==
<lang powershell>$a = [int] (Read-Host a)
<syntaxhighlight lang="powershell">$a = [int] (Read-Host a)
$b = [int] (Read-Host b)
$b = [int] (Read-Host b)


Line 3,228: Line 3,228:
} elseif ($a -gt $b) {
} elseif ($a -gt $b) {
Write-Host $a is greater than $b`.
Write-Host $a is greater than $b`.
}</lang>
}</syntaxhighlight>


=={{header|PureBasic}}==
=={{header|PureBasic}}==
<lang PureBasic>If OpenConsole()
<syntaxhighlight lang="purebasic">If OpenConsole()


Print("Enter an integer: ")
Print("Enter an integer: ")
Line 3,249: Line 3,249:
Input()
Input()
CloseConsole()
CloseConsole()
EndIf</lang>
EndIf</syntaxhighlight>


=={{header|Python}}==
=={{header|Python}}==
<lang Python>#!/usr/bin/env python
<syntaxhighlight lang="python">#!/usr/bin/env python
a = input('Enter value of a: ')
a = input('Enter value of a: ')
b = input('Enter value of b: ')
b = input('Enter value of b: ')
Line 3,261: Line 3,261:
print 'a is greater than b'
print 'a is greater than b'
elif a == b:
elif a == b:
print 'a is equal to b'</lang>
print 'a is equal to b'</syntaxhighlight>


(Note: in Python3 ''input()'' will become ''int(input())'')
(Note: in Python3 ''input()'' will become ''int(input())'')
Line 3,268: Line 3,268:


{{works with|Python|2.x only, not 3.x}}
{{works with|Python|2.x only, not 3.x}}
<lang Python>#!/usr/bin/env python
<syntaxhighlight lang="python">#!/usr/bin/env python
import sys
import sys
try:
try:
Line 3,282: Line 3,282:
1: 'is greater than'
1: 'is greater than'
}
}
print a, dispatch[cmp(a,b)], b</lang>
print a, dispatch[cmp(a,b)], b</syntaxhighlight>


In this case the use of a dispatch table is silly. However, more generally in Python the use of dispatch dictionaries or tables is often preferable to long chains of '''''elif'''' clauses in a condition statement. Python's support of classes and functions (including [[currying]], partial function support, and lambda expressions) as first class objects obviates the need for a "case" or "switch" statement.
In this case the use of a dispatch table is silly. However, more generally in Python the use of dispatch dictionaries or tables is often preferable to long chains of '''''elif'''' clauses in a condition statement. Python's support of classes and functions (including [[currying]], partial function support, and lambda expressions) as first class objects obviates the need for a "case" or "switch" statement.
Line 3,288: Line 3,288:
=={{header|Quackery}}==
=={{header|Quackery}}==


<lang Quackery>$ "Please enter two numbers separated by a space; "
<syntaxhighlight lang="quackery">$ "Please enter two numbers separated by a space; "
input quackery cr
input quackery cr
say "The first number is "
say "The first number is "
Line 3,295: Line 3,295:
2dup < if [ say "smaller than" ] ]
2dup < if [ say "smaller than" ] ]
2drop
2drop
say " the second number." cr</lang>
say " the second number." cr</syntaxhighlight>


{{out}}
{{out}}
Line 3,317: Line 3,317:


=={{header|R}}==
=={{header|R}}==
<lang R>print("insert number a")
<syntaxhighlight lang="r">print("insert number a")
a <- scan(what=numeric(0), nmax=1)
a <- scan(what=numeric(0), nmax=1)
print("insert number b")
print("insert number b")
Line 3,327: Line 3,327:
} else if ( a == b ) { # could be simply else of course...
} else if ( a == b ) { # could be simply else of course...
print("a and b are the same")
print("a and b are the same")
}</lang>
}</syntaxhighlight>


=={{header|Racket}}==
=={{header|Racket}}==
<lang Racket>#lang racket
<syntaxhighlight lang="racket">#lang racket
(define (compare-two-ints a b)
(define (compare-two-ints a b)
(define compared
(define compared
Line 3,338: Line 3,338:
(format "~a ~a ~a" a compared b))
(format "~a ~a ~a" a compared b))
(compare-two-ints (read) (read))</lang>
(compare-two-ints (read) (read))</syntaxhighlight>


=={{header|Raku}}==
=={{header|Raku}}==
(formerly Perl 6)
(formerly Perl 6)
<lang perl6>my $a = prompt("1st int: ").floor;
<syntaxhighlight lang="raku" line>my $a = prompt("1st int: ").floor;
my $b = prompt("2nd int: ").floor;
my $b = prompt("2nd int: ").floor;


Line 3,353: Line 3,353:
elsif $a == $b {
elsif $a == $b {
say 'Equal';
say 'Equal';
}</lang>
}</syntaxhighlight>


With <code><=></code>:
With <code><=></code>:


<lang perl6>say <Less Equal Greater>[($a <=> $b) + 1];</lang>
<syntaxhighlight lang="raku" line>say <Less Equal Greater>[($a <=> $b) + 1];</syntaxhighlight>


A three-way comparison such as <tt><=></tt> actually returns an <code>Order</code> enum which stringifies into 'Decrease', 'Increase' or 'Same'. So if it's ok to use this particular vocabulary, you could say that this task is actually a built in:
A three-way comparison such as <tt><=></tt> actually returns an <code>Order</code> enum which stringifies into 'Decrease', 'Increase' or 'Same'. So if it's ok to use this particular vocabulary, you could say that this task is actually a built in:


<lang perl6>say prompt("1st int: ") <=> prompt("2nd int: ");</lang>
<syntaxhighlight lang="raku" line>say prompt("1st int: ") <=> prompt("2nd int: ");</syntaxhighlight>


=={{header|Rapira}}==
=={{header|Rapira}}==
<lang Rapira>output: "Enter two integers, a and b"
<syntaxhighlight lang="rapira">output: "Enter two integers, a and b"
input: a
input: a
input: b
input: b
Line 3,375: Line 3,375:
when a = b:
when a = b:
output: "a is equal to b"
output: "a is equal to b"
esac</lang>
esac</syntaxhighlight>


=={{header|Raven}}==
=={{header|Raven}}==
<lang Raven>"Enter the first number: " print
<syntaxhighlight lang="raven">"Enter the first number: " print
expect trim 1.1 prefer as $a
expect trim 1.1 prefer as $a
"Enter the second number: " print
"Enter the second number: " print
Line 3,385: Line 3,385:
$a $b < if $b $a "%g is less than %g\n" print
$a $b < if $b $a "%g is less than %g\n" print
$a $b > if $b $a "%g is greater than %g\n" print
$a $b > if $b $a "%g is greater than %g\n" print
$a $b = if $b $a "%g is equal to %g\n" print</lang>
$a $b = if $b $a "%g is equal to %g\n" print</syntaxhighlight>


=={{header|REBOL}}==
=={{header|REBOL}}==
<syntaxhighlight lang="rebol">
<lang REBOL>
REBOL [
REBOL [
Title: "Comparing Two Integers"
Title: "Comparing Two Integers"
Line 3,402: Line 3,402:
]
]
print [a "is" case relation b]
print [a "is" case relation b]
</syntaxhighlight>
</lang>


==={{header|Relation}}===
==={{header|Relation}}===
There is no input, so numbers have to be given in code
There is no input, so numbers have to be given in code
<syntaxhighlight lang="relation">
<lang Relation>
set a = 15
set a = 15
set b = 21
set b = 21
Line 3,418: Line 3,418:
end if
end if
end if
end if
</syntaxhighlight>
</lang>


=={{header|Red}}==
=={{header|Red}}==
{{trans|REBOL}}
{{trans|REBOL}}
<lang rebol>Red [
<syntaxhighlight lang="rebol">Red [
Title: "Comparing Two Integers"
Title: "Comparing Two Integers"
URL: http://rosettacode.org/wiki/Comparing_two_integers
URL: http://rosettacode.org/wiki/Comparing_two_integers
Line 3,435: Line 3,435:
a > b "greater than"
a > b "greater than"
]
]
print [a "is" case relation b]</lang>
print [a "is" case relation b]</syntaxhighlight>


=={{header|ReScript}}==
=={{header|ReScript}}==


<lang ReScript>let my_compare = (a, b) => {
<syntaxhighlight lang="rescript">let my_compare = (a, b) => {
if a < b { "A is less than B" } else
if a < b { "A is less than B" } else
if a > b { "A is greater than B" } else
if a > b { "A is greater than B" } else
Line 3,449: Line 3,449:
let b = int_of_string(Sys.argv[3])
let b = int_of_string(Sys.argv[3])


Js.log(my_compare(a, b))</lang>
Js.log(my_compare(a, b))</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 3,464: Line 3,464:
Taking the numbers from the stack:
Taking the numbers from the stack:


<lang Retro>:example (ab-)
<syntaxhighlight lang="retro">:example (ab-)
dup-pair gt? [ 'A>B s:put nl ] if
dup-pair gt? [ 'A>B s:put nl ] if
dup-pair lt? [ 'A<B s:put nl ] if
dup-pair lt? [ 'A<B s:put nl ] if
eq? [ 'A=B s:put nl ] if ;</lang>
eq? [ 'A=B s:put nl ] if ;</syntaxhighlight>


=={{header|REXX}}==
=={{header|REXX}}==
<lang REXX>/*REXX program prompts for two integers, compares them, and displays the results.*/
<syntaxhighlight lang="rexx">/*REXX program prompts for two integers, compares them, and displays the results.*/
numeric digits 2000 /*for the users that really go ka─razy.*/
numeric digits 2000 /*for the users that really go ka─razy.*/
@=copies('─', 20) /*eyeball catcher for the user's eyen. */
@=copies('─', 20) /*eyeball catcher for the user's eyen. */
Line 3,493: Line 3,493:
end /*forever*/
end /*forever*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
serr: say @ '***error*** ' arg(1); say @ "Please try again."; return</lang>
serr: say @ '***error*** ' arg(1); say @ "Please try again."; return</syntaxhighlight>
{{out|output|text=&nbsp; (shows user input and computer program output together):}}
{{out|output|text=&nbsp; (shows user input and computer program output together):}}
<pre>
<pre>
Line 3,521: Line 3,521:


=={{header|Ring}}==
=={{header|Ring}}==
<lang ring>
<syntaxhighlight lang="ring">
Func Compare a,b
Func Compare a,b
if a < b
if a < b
Line 3,530: Line 3,530:
See "A equals B"
See "A equals B"
ok
ok
</syntaxhighlight>
</lang>


=={{header|Rockstar}}==
=={{header|Rockstar}}==
Line 3,536: Line 3,536:
Minimized Rockstar:
Minimized Rockstar:


<syntaxhighlight lang="rockstar">
<lang Rockstar>
(Get two numbers from user)
(Get two numbers from user)
Listen to Number One
Listen to Number One
Line 3,551: Line 3,551:
If Number One is less than Number Two
If Number One is less than Number Two
Say "The first is less than the second"
Say "The first is less than the second"
</syntaxhighlight>
</lang>


Idiomatic version:
Idiomatic version:
<syntaxhighlight lang="rockstar">
<lang Rockstar>
Listen to your soul
Listen to your soul
Listen to my words
Listen to my words
Line 3,566: Line 3,566:
If your soul is smaller than my words,
If your soul is smaller than my words,
Say "The second was bigger".
Say "The second was bigger".
</syntaxhighlight>
</lang>


=={{header|RPG}}==
=={{header|RPG}}==
Line 3,573: Line 3,573:
CALL rc_intcmp (x'00000000' x'00000001')
CALL rc_intcmp (x'00000000' x'00000001')


<syntaxhighlight lang="rpg">
<lang RPG>
h dftactgrp(*no)
h dftactgrp(*no)


Line 3,596: Line 3,596:
dsply message;
dsply message;
*inlr = *on;
*inlr = *on;
</syntaxhighlight>
</lang>


=={{header|Ruby}}==
=={{header|Ruby}}==
This uses Kernel#gets to get input from STDIN, and String#to_i to convert the string into an integer. (Without this conversion, Ruby would compare strings: 5 < 10 but "5" > "10".)
This uses Kernel#gets to get input from STDIN, and String#to_i to convert the string into an integer. (Without this conversion, Ruby would compare strings: 5 < 10 but "5" > "10".)


<lang ruby>a = (print "enter a value for a: "; gets).to_i
<syntaxhighlight lang="ruby">a = (print "enter a value for a: "; gets).to_i
b = (print "enter a value for b: "; gets).to_i
b = (print "enter a value for b: "; gets).to_i


puts "#{a} is less than #{b}" if a < b
puts "#{a} is less than #{b}" if a < b
puts "#{a} is greater than #{b}" if a > b
puts "#{a} is greater than #{b}" if a > b
puts "#{a} is equal to #{b}" if a == b</lang>
puts "#{a} is equal to #{b}" if a == b</syntaxhighlight>


Another way:
Another way:


<lang ruby>a = (print "enter a value for a: "; gets).to_i
<syntaxhighlight lang="ruby">a = (print "enter a value for a: "; gets).to_i
b = (print "enter a value for b: "; gets).to_i
b = (print "enter a value for b: "; gets).to_i


Line 3,617: Line 3,617:
when 0; puts "#{a} is equal to #{b}"
when 0; puts "#{a} is equal to #{b}"
when +1; puts "#{a} is greater than #{b}"
when +1; puts "#{a} is greater than #{b}"
end</lang>
end</syntaxhighlight>


Example '''input''' and output:
Example '''input''' and output:
Line 3,635: Line 3,635:


An alternative method, which is similar to the python version mentioned above (at the time of writing this) is:
An alternative method, which is similar to the python version mentioned above (at the time of writing this) is:
<lang ruby># Function to make prompts nice and simple to abuse
<syntaxhighlight lang="ruby"># Function to make prompts nice and simple to abuse
def prompt str
def prompt str
print str, ": "
print str, ": "
Line 3,658: Line 3,658:


# I hope you can figure this out
# I hope you can figure this out
puts "#{a} is #{dispatch[a<=>b]} #{b}"</lang>
puts "#{a} is #{dispatch[a<=>b]} #{b}"</syntaxhighlight>


=={{header|Run BASIC}}==
=={{header|Run BASIC}}==
<lang runbasic>input "1st number:"; n1
<syntaxhighlight lang="runbasic">input "1st number:"; n1
input "2nd number:"; n2
input "2nd number:"; n2


if n1 < n2 then print "1st number ";n1;" is less than 2nd number";n2
if n1 < n2 then print "1st number ";n1;" is less than 2nd number";n2
if n1 > n2 then print "1st number ";n1;" is greater than 2nd number";n2
if n1 > n2 then print "1st number ";n1;" is greater than 2nd number";n2
if n1 = n2 then print "1st number ";n1;" is equal to 2nd number";n2</lang>
if n1 = n2 then print "1st number ";n1;" is equal to 2nd number";n2</syntaxhighlight>


=={{header|Rust}}==
=={{header|Rust}}==
Reading from stdin into a string is cumbersome at the moment, but convenience functions will be implemented in the future.
Reading from stdin into a string is cumbersome at the moment, but convenience functions will be implemented in the future.
<lang rust>use std::io::{self, BufRead};
<syntaxhighlight lang="rust">use std::io::{self, BufRead};


fn main() {
fn main() {
Line 3,688: Line 3,688:
println!("{} is greater than {}" , a , b)
println!("{} is greater than {}" , a , b)
};
};
}</lang>
}</syntaxhighlight>


=={{header|SAS}}==
=={{header|SAS}}==
<lang sas>/* Showing operators and their fortran-like equivalents. Note that ~= and ^= both mean "different" */
<syntaxhighlight lang="sas">/* Showing operators and their fortran-like equivalents. Note that ~= and ^= both mean "different" */
data _null_;
data _null_;
input a b;
input a b;
Line 3,713: Line 3,713:
1 1
1 1
;
;
run;</lang>
run;</syntaxhighlight>


=={{header|Scala}}==
=={{header|Scala}}==
<lang scala>object IntCompare {
<syntaxhighlight lang="scala">object IntCompare {
def main(args: Array[String]): Unit = {
def main(args: Array[String]): Unit = {
val a=Console.readInt
val a=Console.readInt
Line 3,727: Line 3,727:
printf("%d is greater than %d\n", a, b)
printf("%d is greater than %d\n", a, b)
}
}
}</lang>
}</syntaxhighlight>


=={{header|Scheme}}==
=={{header|Scheme}}==
<lang scheme>(define (my-compare a b)
<syntaxhighlight lang="scheme">(define (my-compare a b)
(cond ((< a b) "A is less than B")
(cond ((< a b) "A is less than B")
((> a b) "A is greater than B")
((> a b) "A is greater than B")
((= a b) "A equals B")))
((= a b) "A equals B")))


(my-compare (read) (read))</lang>
(my-compare (read) (read))</syntaxhighlight>


=={{header|Seed7}}==
=={{header|Seed7}}==
<lang seed7>$ include "seed7_05.s7i";
<syntaxhighlight lang="seed7">$ include "seed7_05.s7i";


const proc: main is func
const proc: main is func
Line 3,759: Line 3,759:
writeln(a <& " is greater than " <& b);
writeln(a <& " is greater than " <& b);
end if;
end if;
end func;</lang>
end func;</syntaxhighlight>


=={{header|SenseTalk}}==
=={{header|SenseTalk}}==


<lang sensetalk>Ask "Provide Any Number"
<syntaxhighlight lang="sensetalk">Ask "Provide Any Number"


Put It into A
Put It into A
Line 3,781: Line 3,781:
If A is Equal to B
If A is Equal to B
Put A& " is Equal to " &B
Put A& " is Equal to " &B
End If</lang>
End If</syntaxhighlight>


=={{header|Sidef}}==
=={{header|Sidef}}==
<lang ruby>var a = read("a: ", Number);
<syntaxhighlight lang="ruby">var a = read("a: ", Number);
var b = read("b: ", Number);
var b = read("b: ", Number);


Line 3,795: Line 3,795:
elsif (a > b) {
elsif (a > b) {
say 'Greater';
say 'Greater';
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 3,805: Line 3,805:
=={{header|Slate}}==
=={{header|Slate}}==
<lang slate>[ |:a :b |
<syntaxhighlight lang="slate">[ |:a :b |


( a > b ) ifTrue: [ inform: 'a greater than b\n' ].
( a > b ) ifTrue: [ inform: 'a greater than b\n' ].
Line 3,811: Line 3,811:
( a = b ) ifTrue: [ inform: 'a is equal to b\n' ].
( a = b ) ifTrue: [ inform: 'a is equal to b\n' ].


] applyTo: {Integer readFrom: (query: 'Enter a: '). Integer readFrom: (query: 'Enter b: ')}.</lang>
] applyTo: {Integer readFrom: (query: 'Enter a: '). Integer readFrom: (query: 'Enter b: ')}.</syntaxhighlight>


=={{header|Smalltalk}}==
=={{header|Smalltalk}}==


<lang smalltalk>| a b |
<syntaxhighlight lang="smalltalk">| a b |
'a = ' display. a := (stdin nextLine asInteger).
'a = ' display. a := (stdin nextLine asInteger).
'b = ' display. b := (stdin nextLine asInteger).
'b = ' display. b := (stdin nextLine asInteger).
( a > b ) ifTrue: [ 'a greater than b' displayNl ].
( a > b ) ifTrue: [ 'a greater than b' displayNl ].
( a < b ) ifTrue: [ 'a less than b' displayNl ].
( a < b ) ifTrue: [ 'a less than b' displayNl ].
( a = b ) ifTrue: [ 'a is equal to b' displayNl ].</lang>
( a = b ) ifTrue: [ 'a is equal to b' displayNl ].</syntaxhighlight>


=={{header|SNOBOL4}}==
=={{header|SNOBOL4}}==
Line 3,826: Line 3,826:
Comparisons in Snobol are not operators, but predicate functions that return a null string and generate a success or failure value which allows or blocks statement execution, and which can be tested for branching. Other numeric comparisons are ge (>=), le (<=) and ne (!= ). There is also a parallel set of L-prefixed predicates in modern Snobols for lexical string comparison.
Comparisons in Snobol are not operators, but predicate functions that return a null string and generate a success or failure value which allows or blocks statement execution, and which can be tested for branching. Other numeric comparisons are ge (>=), le (<=) and ne (!= ). There is also a parallel set of L-prefixed predicates in modern Snobols for lexical string comparison.


<lang SNOBOL4>* # Get user input
<syntaxhighlight lang="snobol4">* # Get user input
output = 'Enter X,Y:'
output = 'Enter X,Y:'
trim(input) break(',') . x ',' rem . y
trim(input) break(',') . x ',' rem . y
Line 3,833: Line 3,833:
output = eq(x,y) x ' is equal to ' y :s(end)
output = eq(x,y) x ' is equal to ' y :s(end)
output = gt(x,y) x ' is greater than ' y
output = gt(x,y) x ' is greater than ' y
end</lang>
end</syntaxhighlight>


=={{header|SNUSP}}==
=={{header|SNUSP}}==
There are no built-in comparison operators, but you can (destructively) check which of two adjacent cells is most positive.
There are no built-in comparison operators, but you can (destructively) check which of two adjacent cells is most positive.
<lang snusp>++++>++++ a b !/?\<?\# a=b
<syntaxhighlight lang="snusp">++++>++++ a b !/?\<?\# a=b
> - \# a>b
> - \# a>b
- <
- <
a<b #\?/</lang>
a<b #\?/</syntaxhighlight>


=={{header|Sparkling}}==
=={{header|Sparkling}}==
<lang sparkling>let a = 13, b = 37;
<syntaxhighlight lang="sparkling">let a = 13, b = 37;
if a < b {
if a < b {
print("a < b");
print("a < b");
Line 3,852: Line 3,852:
} else {
} else {
print("either a or b or both are NaN");
print("either a or b or both are NaN");
}</lang>
}</syntaxhighlight>


=={{header|SQL}}==
=={{header|SQL}}==
{{works with|Oracle}}
{{works with|Oracle}}
<lang sql>
<syntaxhighlight lang="sql">
drop table test;
drop table test;


Line 3,878: Line 3,878:
from test
from test
where a > b;
where a > b;
</syntaxhighlight>
</lang>


<pre>
<pre>
Line 3,900: Line 3,900:
{{works with|Db2 LUW}}
{{works with|Db2 LUW}}
With SQL only:
With SQL only:
<lang sql pl>
<syntaxhighlight lang="sql pl">
CREATE TABLE TEST (
CREATE TABLE TEST (
VAL1 INT,
VAL1 INT,
Line 3,916: Line 3,916:
END COMPARISON
END COMPARISON
FROM TEST;
FROM TEST;
</syntaxhighlight>
</lang>
Output:
Output:
<pre>
<pre>
Line 3,948: Line 3,948:
{{works with|Db2 LUW}} version 9.7 or higher.
{{works with|Db2 LUW}} version 9.7 or higher.
With SQL PL:
With SQL PL:
<lang sql pl>
<syntaxhighlight lang="sql pl">
--#SET TERMINATOR @
--#SET TERMINATOR @


Line 3,966: Line 3,966:
CALL COMPARISON(2, 2) @
CALL COMPARISON(2, 2) @
CALL COMPARISON(2, 1) @
CALL COMPARISON(2, 1) @
</syntaxhighlight>
</lang>
Output:
Output:
<pre>
<pre>
Line 4,018: Line 4,018:
halt</pre>
halt</pre>
To run the SSEM program, load A into storage address 21 and B into storage address 22. No additional space is used. Like the pseudocode version, the program halts with the accumulator holding 1 if A>B, 0 if A=B, or -1 if A<B.
To run the SSEM program, load A into storage address 21 and B into storage address 22. No additional space is used. Like the pseudocode version, the program halts with the accumulator holding 1 if A>B, 0 if A=B, or -1 if A<B.
<lang ssem>10101000000000100000000000000000 0. -21 to c
<syntaxhighlight lang="ssem">10101000000000100000000000000000 0. -21 to c
10101000000001100000000000000000 1. c to 21
10101000000001100000000000000000 1. c to 21
10101000000000100000000000000000 2. -21 to c
10101000000000100000000000000000 2. -21 to c
Line 4,038: Line 4,038:
11111111111111111111111111111111 18. -1
11111111111111111111111111111111 18. -1
11010000000000000000000000000000 19. 11
11010000000000000000000000000000 19. 11
10110000000000000000000000000000 20. 13</lang>
10110000000000000000000000000000 20. 13</syntaxhighlight>


=={{header|Standard ML}}==
=={{header|Standard ML}}==
<lang sml>fun compare_integers(a, b) =
<syntaxhighlight lang="sml">fun compare_integers(a, b) =
if a < b then print "A is less than B\n"
if a < b then print "A is less than B\n"
if a > b then print "A is greater than B\n"
if a > b then print "A is greater than B\n"
Line 4,054: Line 4,054:
compare_integers (a, b)
compare_integers (a, b)
end
end
handle Bind => print "Invalid number entered!\n"</lang>
handle Bind => print "Invalid number entered!\n"</syntaxhighlight>
A more idiomatic and less error-prone way to do it in SML would be to use a compare function that returns type <tt>order</tt>, which is either LESS, GREATER, or EQUAL:
A more idiomatic and less error-prone way to do it in SML would be to use a compare function that returns type <tt>order</tt>, which is either LESS, GREATER, or EQUAL:
<lang sml>fun myCompare (a, b) = case Int.compare (a, b) of
<syntaxhighlight lang="sml">fun myCompare (a, b) = case Int.compare (a, b) of
LESS => "A is less than B"
LESS => "A is less than B"
| GREATER => "A is greater than B"
| GREATER => "A is greater than B"
| EQUAL => "A equals B"</lang>
| EQUAL => "A equals B"</syntaxhighlight>


=={{header|Swift}}==
=={{header|Swift}}==
<lang Swift>import Cocoa
<syntaxhighlight lang="swift">import Cocoa


var input = NSFileHandle.fileHandleWithStandardInput()
var input = NSFileHandle.fileHandleWithStandardInput()
Line 4,078: Line 4,078:
if (a==b) {println("\(a) equals \(b)")}
if (a==b) {println("\(a) equals \(b)")}
if (a < b) {println("\(a) is less than \(b)")}
if (a < b) {println("\(a) is less than \(b)")}
if (a > b) {println("\(a) is greater than \(b)")}</lang>
if (a > b) {println("\(a) is greater than \(b)")}</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 4,089: Line 4,089:
This is not how one would write this in Tcl, but for the sake of clarity:
This is not how one would write this in Tcl, but for the sake of clarity:


<lang tcl>puts "Please enter two numbers:"
<syntaxhighlight lang="tcl">puts "Please enter two numbers:"


gets stdin x
gets stdin x
Line 4,096: Line 4,096:
if { $x > $y } { puts "$x is greater than $y" }
if { $x > $y } { puts "$x is greater than $y" }
if { $x < $y } { puts "$x is less than $y" }
if { $x < $y } { puts "$x is less than $y" }
if { $x == $y } { puts "$x equals $y" }</lang>
if { $x == $y } { puts "$x equals $y" }</syntaxhighlight>


Other comparison operators are "<=", ">=" and "!=".
Other comparison operators are "<=", ">=" and "!=".
Line 4,102: Line 4,102:
Note that Tcl doesn't really have a notion of a variable "type" - all variables are just strings of bytes and notions like "integer" only ever enter at interpretation time. Thus the above code will work correctly for "5" and "6", but "5" and "5.5" will also be compared correctly. It will not be an error to enter "hello" for one of the numbers ("hello" is greater than any integer). If this is a problem, the type can be expressly cast
Note that Tcl doesn't really have a notion of a variable "type" - all variables are just strings of bytes and notions like "integer" only ever enter at interpretation time. Thus the above code will work correctly for "5" and "6", but "5" and "5.5" will also be compared correctly. It will not be an error to enter "hello" for one of the numbers ("hello" is greater than any integer). If this is a problem, the type can be expressly cast


<lang tcl>if {int($x) > int($y)} { puts "$x is greater than $y" }</lang>
<syntaxhighlight lang="tcl">if {int($x) > int($y)} { puts "$x is greater than $y" }</syntaxhighlight>


or otherwise [[IsNumeric | type can be checked]] with "<tt>if { string is integer $x }...</tt>"
or otherwise [[IsNumeric | type can be checked]] with "<tt>if { string is integer $x }...</tt>"
Line 4,109: Line 4,109:


A variant that iterates over comparison operators, demonstrated in an interactive [[tclsh]]:
A variant that iterates over comparison operators, demonstrated in an interactive [[tclsh]]:
<lang Tcl>% set i 5;set j 6
<syntaxhighlight lang="tcl">% set i 5;set j 6
% foreach {o s} {< "less than" > "greater than" == equal} {if [list $i $o $j] {puts "$i is $s $j"}}
% foreach {o s} {< "less than" > "greater than" == equal} {if [list $i $o $j] {puts "$i is $s $j"}}
5 is less than 6
5 is less than 6
Line 4,117: Line 4,117:
% set j 4
% set j 4
% foreach {o s} {< "less than" > "greater than" == equal} {if [list $i $o $j] {puts "$i is $s $j"}}
% foreach {o s} {< "less than" > "greater than" == equal} {if [list $i $o $j] {puts "$i is $s $j"}}
5 is greater than 4</lang>
5 is greater than 4</syntaxhighlight>


=={{header|TI-83 BASIC}}==
=={{header|TI-83 BASIC}}==
<lang ti83b>Prompt A,B
<syntaxhighlight lang="ti83b">Prompt A,B
If A<B: Disp "A SMALLER B"
If A<B: Disp "A SMALLER B"
If A>B: Disp "A GREATER B"
If A>B: Disp "A GREATER B"
If A=B: Disp "A EQUAL B"</lang>
If A=B: Disp "A EQUAL B"</syntaxhighlight>


=={{header|TI-89 BASIC}}==
=={{header|TI-89 BASIC}}==


<lang ti89b>Local a, b, result
<syntaxhighlight lang="ti89b">Local a, b, result
Prompt a, b
Prompt a, b
If a < b Then
If a < b Then
Line 4,138: Line 4,138:
"???" → result
"???" → result
EndIf
EndIf
Disp string(a) & " " & result & " " & string(b)</lang>
Disp string(a) & " " & result & " " & string(b)</syntaxhighlight>


=={{header|Toka}}==
=={{header|Toka}}==
<lang toka>[ ( a b -- )
<syntaxhighlight lang="toka">[ ( a b -- )
2dup < [ ." a is less than b\n" ] ifTrue
2dup < [ ." a is less than b\n" ] ifTrue
2dup > [ ." a is greater than b\n" ] ifTrue
2dup > [ ." a is greater than b\n" ] ifTrue
Line 4,149: Line 4,149:
1 1 compare-integers
1 1 compare-integers
2 1 compare-integers
2 1 compare-integers
1 2 compare-integers</lang>
1 2 compare-integers</syntaxhighlight>


=={{header|TUSCRIPT}}==
=={{header|TUSCRIPT}}==
<lang tuscript>
<syntaxhighlight lang="tuscript">
$$ MODE TUSCRIPT
$$ MODE TUSCRIPT


Line 4,163: Line 4,163:
IF (i1<i2) PRINT i1," is less than ",i2
IF (i1<i2) PRINT i1," is less than ",i2
IF (i1>i2) PRINT i1," is greater than ",i2
IF (i1>i2) PRINT i1," is greater than ",i2
</syntaxhighlight>
</lang>


=={{header|UNIX Shell}}==
=={{header|UNIX Shell}}==
Line 4,170: Line 4,170:
{{works with|ksh93}}
{{works with|ksh93}}


<lang bash>#!/bin/ksh
<syntaxhighlight lang="bash">#!/bin/ksh
# tested with ksh93s+
# tested with ksh93s+


Line 4,191: Line 4,191:
fi
fi


exit 0</lang>
exit 0</syntaxhighlight>


One can backport the previous code to pdksh, which has no builtin printf, but can call /usr/bin/printf as an external program.
One can backport the previous code to pdksh, which has no builtin printf, but can call /usr/bin/printf as an external program.
Line 4,197: Line 4,197:
{{works with|pdksh}}
{{works with|pdksh}}


<lang bash>#!/bin/ksh
<syntaxhighlight lang="bash">#!/bin/ksh
# tested with pdksh
# tested with pdksh


Line 4,216: Line 4,216:
fi
fi


exit 0</lang>
exit 0</syntaxhighlight>


----
----
Line 4,222: Line 4,222:
{{works with|Bash}}
{{works with|Bash}}


<lang bash>read -p "Enter two integers: " a b
<syntaxhighlight lang="bash">read -p "Enter two integers: " a b


if [ $a -gt $b ]; then comparison="greater than"
if [ $a -gt $b ]; then comparison="greater than"
Line 4,230: Line 4,230:
fi
fi


echo "${a} is ${comparison} ${b}"</lang>
echo "${a} is ${comparison} ${b}"</syntaxhighlight>


=={{header|Ursa}}==
=={{header|Ursa}}==
<lang ursa>decl int first second
<syntaxhighlight lang="ursa">decl int first second
out "enter first integer: " console
out "enter first integer: " console
set first (in int console)
set first (in int console)
Line 4,247: Line 4,247:
if (> first second)
if (> first second)
out first " is greater than " second endl console
out first " is greater than " second endl console
end if</lang>
end if</syntaxhighlight>


=={{header|V}}==
=={{header|V}}==
<lang v>[compare
<syntaxhighlight lang="v">[compare
[ [>] ['less than' puts]
[ [>] ['less than' puts]
[<] ['greater than' puts]
[<] ['greater than' puts]
Line 4,261: Line 4,261:
less than
less than
|2 2 compare
|2 2 compare
is equal</lang>
is equal</syntaxhighlight>


=={{header|Vala}}==
=={{header|Vala}}==
<lang vala>
<syntaxhighlight lang="vala">
void main(){
void main(){
int a;
int a;
Line 4,282: Line 4,282:
stdout.printf("%d is greater than %d\n", a, b);
stdout.printf("%d is greater than %d\n", a, b);
}
}
</syntaxhighlight>
</lang>


=={{header|VBA}}==
=={{header|VBA}}==
<lang vb>Public Sub integer_comparison()
<syntaxhighlight lang="vb">Public Sub integer_comparison()
first_integer = CInt(InputBox("Give me an integer."))
first_integer = CInt(InputBox("Give me an integer."))
second_integer = CInt(InputBox("Give me another integer."))
second_integer = CInt(InputBox("Give me another integer."))
Line 4,291: Line 4,291:
Debug.Print IIf(first_integer = second_integer, "first integer is equal to second integer", "first integer is not equal to second integer")
Debug.Print IIf(first_integer = second_integer, "first integer is equal to second integer", "first integer is not equal to second integer")
Debug.Print IIf(first_integer > second_integer, "first integer is bigger than second integer", "first integer is not bigger than second integer")
Debug.Print IIf(first_integer > second_integer, "first integer is bigger than second integer", "first integer is not bigger than second integer")
End Sub</lang>
End Sub</syntaxhighlight>


=={{header|VBScript}}==
=={{header|VBScript}}==
Based on the BASIC
Based on the BASIC
=====Implementation=====
=====Implementation=====
<syntaxhighlight lang="vb">
<lang vb>
option explicit
option explicit


Line 4,324: Line 4,324:
eef( a = b, "equal to ", _
eef( a = b, "equal to ", _
eef( a > b, "greater than ", vbnullstring ) ) ) & "Second integer."
eef( a > b, "greater than ", vbnullstring ) ) ) & "Second integer."
</syntaxhighlight>
</lang>


=={{header|Visual Basic .NET}}==
=={{header|Visual Basic .NET}}==
Line 4,330: Line 4,330:


{{works with|Visual Basic .NET|9.0+}}
{{works with|Visual Basic .NET|9.0+}}
<lang vbnet>Sub Main()
<syntaxhighlight lang="vbnet">Sub Main()


Dim a = CInt(Console.ReadLine)
Dim a = CInt(Console.ReadLine)
Line 4,350: Line 4,350:
End Select
End Select


End Sub</lang>
End Sub</syntaxhighlight>


=={{header|Wart}}==
=={{header|Wart}}==
<lang wart>a <- (read)
<syntaxhighlight lang="wart">a <- (read)
b <- (read)
b <- (read)
prn (if (a < b)
prn (if (a < b)
Line 4,360: Line 4,360:
: "a is greater than b"
: "a is greater than b"
:else
:else
: "a equals b")</lang>
: "a equals b")</syntaxhighlight>


=={{header|Wren}}==
=={{header|Wren}}==
<lang ecmascript>import "io" for Stdin, Stdout
<syntaxhighlight lang="ecmascript">import "io" for Stdin, Stdout


System.print("Enter anything other than a number to quit at any time.\n")
System.print("Enter anything other than a number to quit at any time.\n")
Line 4,384: Line 4,384:
}
}
System.print()
System.print()
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 4,407: Line 4,407:


=={{header|XLISP}}==
=={{header|XLISP}}==
<lang xlisp>(DEFUN COMPARE-INTEGERS ()
<syntaxhighlight lang="xlisp">(DEFUN COMPARE-INTEGERS ()
(DISPLAY "Enter two integers separated by a space.")
(DISPLAY "Enter two integers separated by a space.")
(NEWLINE)
(NEWLINE)
Line 4,416: Line 4,416:
((> A B) (DISPLAY "The first number is larger."))
((> A B) (DISPLAY "The first number is larger."))
((= A B) (DISPLAY "They are equal."))
((= A B) (DISPLAY "They are equal."))
((< A B) (DISPLAY "The first number is smaller."))))</lang>
((< A B) (DISPLAY "The first number is smaller."))))</syntaxhighlight>


=={{header|XPL0}}==
=={{header|XPL0}}==
<lang XPL0>code IntIn=10, Text=12;
<syntaxhighlight lang="xpl0">code IntIn=10, Text=12;
int A, B;
int A, B;
[A:= IntIn(0);
[A:= IntIn(0);
Line 4,427: Line 4,427:
if A>B then Text(0, "A>B");
if A>B then Text(0, "A>B");
CrLf(0);
CrLf(0);
]</lang>
]</syntaxhighlight>


=={{header|XSLT}}==
=={{header|XSLT}}==
Because XSLT uses XML syntax, the less than and greater than operators which would normally be written '<' and '>' must be escaped using character entities, even inside of XPath expressions.
Because XSLT uses XML syntax, the less than and greater than operators which would normally be written '<' and '>' must be escaped using character entities, even inside of XPath expressions.


<lang xml><xsl:template name="compare">
<syntaxhighlight lang="xml"><xsl:template name="compare">
<xsl:param name="a" select="1"/>
<xsl:param name="a" select="1"/>
<xsl:param name="b" select="2"/>
<xsl:param name="b" select="2"/>
Line 4,442: Line 4,442:
</xsl:choose>
</xsl:choose>
</fo:block>
</fo:block>
</xsl:template></lang>
</xsl:template></syntaxhighlight>


=={{header|zkl}}==
=={{header|zkl}}==
<lang zkl>var x,y; x,y=ask("Two ints: ").split(" ").apply("toInt")
<syntaxhighlight lang="zkl">var x,y; x,y=ask("Two ints: ").split(" ").apply("toInt")
(if (x==y) "equal" else if (x<y) "less" else if(x>y) "greater").println()</lang>
(if (x==y) "equal" else if (x<y) "less" else if(x>y) "greater").println()</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 4,454: Line 4,454:


=={{header|ZX Spectrum Basic}}==
=={{header|ZX Spectrum Basic}}==
<lang zxbasic>10 INPUT "Enter two integers: ";a;" ";b
<syntaxhighlight lang="zxbasic">10 INPUT "Enter two integers: ";a;" ";b
20 PRINT a;" is ";("less than " AND (a<b));("equal to " AND (a=b));("greather than " AND (a>b));b</lang>
20 PRINT a;" is ";("less than " AND (a<b));("equal to " AND (a=b));("greather than " AND (a>b));b</syntaxhighlight>