Integer comparison: Difference between revisions

m
→‎{{header|Wren}}: Changed to Wren S/H
m (→‎{{header|Wren}}: Changed to Wren S/H)
 
(46 intermediate revisions by 28 users not shown)
Line 19:
*   [[String comparison]]
<br><br>
 
=={{header|11l}}==
<syntaxhighlight lang="11l">V a = Int(input(‘Enter value of a: ’))
V b = Int(input(‘Enter value of b: ’))
 
I a < b
print(‘a is less than b’)
I a > b
print(‘a is greater than b’)
I a == b
print(‘a is equal to b’)</syntaxhighlight>
 
=={{header|360 Assembly}}==
Input is done by a standard register 1 pointed parameter list.
<langsyntaxhighlight lang="360asm">INTCOMP PROLOG
* Reg1=Addr(Addr(argA),Addr(argB))
L 2,0(1) Reg2=Addr(argA)
Line 54 ⟶ 65:
A DS F 31-bit signed integer
B DS F 31-bit signed integer
END</langsyntaxhighlight>
 
=={{header|6502 Assembly}}==
Code is called as a subroutine (i.e. JSR Compare).
Specific OS/hardware routines for user input and printing are left unimplemented.
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
;integers to compare now in memory locations A and B
Line 73 ⟶ 85:
A_equals_B: JSR DisplayAEqualsB ;routine not implemented
Done: PLA ;restore Accumulator from stack
RTS ;return from subroutine</langsyntaxhighlight>
 
=={{header|68000 Assembly}}==
The task of getting input from the user is much more difficult in assembly since it hasn't been done for you unlike nearly all other languages. So that part will be omitted to focus on the actual comparison.
 
In assembly, the only difference between a signed integer and an unsigned integer is the comparator(s) used to evaluate it. Therefore we have two different versions of this task.
 
===Unsigned Comparison===
<syntaxhighlight lang="68000devpac">Compare:
;integers to compare are in D0 and D1
CMP.L D1,D0
BCS .less ;D1 < D0
;else, carry clear, which implies greater than or equal to.
BNE .greater ;D1 > D0
;else, d1 = d0
LEA Equal,A0
JMP PrintString ;and use its RTS to return
.greater:
LEA GreaterThan,A0
JMP PrintString ;and use its RTS to return
.less:
LEA LessThan,A0
JMP PrintString ;and use its RTS to return
 
 
LessThan:
dc.b "second integer less than first",0
even
GreaterThan:
dc.b "second integer greater than first",0
even
Equal:
dc.b "both are equal",0
even</syntaxhighlight>
 
===Signed Comparison===
<syntaxhighlight lang="68000devpac">Compare:
;integers to compare are in D0 and D1
CMP.L D1,D0
BLT .less ;D1 < D0
;else, carry clear, which implies greater than or equal to.
BNE .greater ;D1 > D0
;else, d1 = d0
LEA Equal,A0
JMP PrintString ;and use its RTS to return
.greater:
LEA GreaterThan,A0
JMP PrintString ;and use its RTS to return
.less:
LEA LessThan,A0
JMP PrintString ;and use its RTS to return
 
 
LessThan:
dc.b "second integer less than first",0
even
GreaterThan:
dc.b "second integer greater than first",0
even
Equal:
dc.b "both are equal",0
even</syntaxhighlight>
 
=={{header|8051 Assembly}}==
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'.
<langsyntaxhighlight lang="asm">compare:
push psw
cjne a, b, clt
Line 94 ⟶ 167:
compare_:
pop psw
ret</langsyntaxhighlight>
Testing for (a <= b) or (a >= b) can be performed by changing the jumps.
 
=={{header|8th}}==
The user would put the numbers on the stack and then invoke 'compare':
<langsyntaxhighlight lang="forth">
: compare \ n m --
2dup n:= if "They are equal" . cr then
2dup n:< if "First less than second" . cr then
n:> if "First greater than second" . cr then ;
</syntaxhighlight>
</lang>
Alternatively one could use the "n:cmp" word
 
Line 110 ⟶ 183:
{{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>).
<langsyntaxhighlight ARM_Assemblylang="arm_assembly">.equ STDOUT, 1
.equ SVC_WRITE, 64
.equ SVC_EXIT, 93
Line 173 ⟶ 246:
_exit:
mov x8, #SVC_EXIT
svc #0</langsyntaxhighlight>
 
=={{header|ABAP}}==
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.
 
Line 192 ⟶ 265:
 
write comparison_result.
</syntaxhighlight>
</lang>
 
=={{header|Action!}}==
<syntaxhighlight lang="action!">PROC Main()
INT a,b
 
Print("Input value of a:") a=InputI()
Print("Input value of b:") b=InputI()
 
IF a<b THEN
PrintF("%I is less than %I%E",a,b)
FI
IF a>b THEN
PrintF("%I is greater than %I%E",a,b)
FI
IF a=b THEN
PrintF("%I is equal to %I%E",a,b)
FI
RETURN</syntaxhighlight>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Integer_comparison.png Screenshot from Atari 8-bit computer]
<pre>
Input value of a:123
Input value of b:4712
123 is less than 4712
</pre>
 
=={{header|Ada}}==
<langsyntaxhighlight lang="ada">with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_Io;
 
Line 218 ⟶ 316:
Put_Line("A is greater than B");
end if;
end Compare_Ints;</langsyntaxhighlight>
 
=={{header|Aime}}==
<langsyntaxhighlight lang="aime">void
output(integer a, integer b, text condition)
{
Line 247 ⟶ 345:
 
return 0;
}</langsyntaxhighlight>
Run as:
<pre>aime FILE integer a 33 integer b 133</pre>
Line 265 ⟶ 363:
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).
<langsyntaxhighlight lang="algol68">main: (
INT a, b;
read((a, space, b, new line));
Line 285 ⟶ 383:
print((a," is greater or equal to ", b, new line))
FI
)</langsyntaxhighlight>
{{out}}
<pre>
Line 294 ⟶ 392:
 
=={{header|ALGOL W}}==
<langsyntaxhighlight lang="algolw">begin
 
integer a, b;
Line 307 ⟶ 405:
if a > b then write( a, " is greater than ", b );
 
end.</langsyntaxhighlight>
 
=={{header|AppleScript}}==
<langsyntaxhighlight AppleScriptlang="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 msg to {n1}
Line 321 ⟶ 419:
end if
set end of msg to n2
return msg as string</langsyntaxhighlight>
 
Or...
<langsyntaxhighlight AppleScriptlang="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
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 greater than " & n2</langsyntaxhighlight>
 
=={{header|ARM Assembly}}==
{{works with|as|Raspberry Pi}}
<syntaxhighlight lang="arm assembly">
<lang ARM Assembly>
 
/* ARM assembly Raspberry PI */
Line 516 ⟶ 614:
szMessErrDep: .asciz "Too large: overflow 32 bits.\n"
 
</syntaxhighlight>
</lang>
 
=={{header|Arturo}}==
<langsyntaxhighlight arturolang="rebol">printa: to :integer input "enter a value for a: "
b: to :integer input "enter a value for b: "
a: toNumber|strip|input ~
 
if a<b [ print "enter[ a value"is forless b:than" b ] ]
if a>b [ print [ a "is greater than" b ] ]
b: toNumber|strip|input ~
if a=b [ print [ a "is equal to" b ] ]</syntaxhighlight>
 
if a<b { print a + " is less than " + b }
if a>b { print a + " is greater than " + b }
if a=b { print a + " is equal to " + b }}</lang>
{{out}}
<pre>enter a value for a:
10
enter a value for b:
20
10 is less than 20</pre>
 
=={{header|Astro}}==
<langsyntaxhighlight lang="python">let a = input('Enter value of a: ')
let b = input('Enter value of b: ')
 
Line 544 ⟶ 633:
print 'a is greater than b'
elif a == b:
print 'a is equal to b'</langsyntaxhighlight>
 
=={{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.
The default range is 0 to 100.
<langsyntaxhighlight lang="autohotkey">Gui, Add, Edit
Gui, Add, UpDown, vVar1
Gui, Add, Edit
Line 568 ⟶ 657:
 
GuiClose:
ExitApp</langsyntaxhighlight>
 
=={{header|Avail}}==
<langsyntaxhighlight Availlang="avail">// This code doesn't try to protect against any malformed input.
a ::= next line from standard input→integer;
b ::= next line from standard input→integer;
If a > b then [Print: "a > b";]
else if a < b then [Print: "a < b";]
else if a = b then [Print: "a = b";];</langsyntaxhighlight>
 
=={{header|AWK}}==
<langsyntaxhighlight lang="awk">/[0-9]* [0-9]*/{
if ($1 == $2) print $1, "is equal to", $2
if ($1 < $2) print $1, "is less than", $2
if ($1 > $2) print $1, "is greater than", $2
}</langsyntaxhighlight>
 
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:
 
<langsyntaxhighlight 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</langsyntaxhighlight>
 
=={{header|Axe}}==
<langsyntaxhighlight lang="axe">Lbl FUNC
If r₁<r₂
Disp "LESS THAN",i
Line 602 ⟶ 691:
Disp "GREATER THAN",i
End
Return</langsyntaxhighlight>
 
=={{header|BASIC}}==
==={{header|Applesoft BASIC}}===
<syntaxhighlight lang="applesoftbasic">10 INPUT "ENTER TWO INTEGERS: "; A%, B%
20 A$(0) = "NOT "
30 PRINT A% " IS " A$(A% < B%) "LESS THAN " B%
40 PRINT A% " IS " A$(A% = B%) "EQUAL TO " B%
50 PRINT A% " IS " A$(A% > B%) "GREATER THAN " B%</syntaxhighlight>
 
==={{header|BaCon}}===
<langsyntaxhighlight lang="freebasic">
INPUT "Enter first number " ,a
INPUT "Enter second number " ,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 greater than ", b</langsyntaxhighlight>
 
 
{{works with|QuickBasic|4.5}}
<langsyntaxhighlight lang="qbasic">CLS
INPUT "a, b"; a, b 'remember to type the comma when you give the numbers
PRINT "a is ";
Line 622 ⟶ 716:
IF a = b THEN PRINT "equal to ";
IF a > b THEN PRINT "greater than ";
PRINT "b"</langsyntaxhighlight>
 
==={{header|Applesoft BASICBASIC256}}===
<syntaxhighlight lang="freebasic">input "Please enter one integer: ", x
<lang ApplesoftBasic>10 INPUT "ENTER TWO INTEGERS: "; A%, B%
input "and a second integer: ", y
20 A$(0) = "NOT "
30if PRINTx A%< "y ISthen "print A$(A%x; <" B%)is "LESSless THANthan "; B%y
40if PRINTx A%= "y ISthen "print A$(A%x; =" B%)is "EQUALequal TOto "; B%y
50if PRINTx A%> "y ISthen "print A$(A%x; >" B%)is "GREATERgreater THANthan "; B%y</langsyntaxhighlight>
 
==={{header|BBC BASIC}}===
<syntaxhighlight lang="bbcbasic"> INPUT "Enter two numbers separated by a comma: " a, b
CASE TRUE OF
WHEN a < b: PRINT ;a " is less than "; b
WHEN a = b: PRINT ;a " is equal to "; b
WHEN a > b: PRINT ;a " is greater than "; b
ENDCASE</syntaxhighlight>
 
==={{header|FreeBASIC}}===
<syntaxhighlight lang="freebasic">' FB 1.05.0 Win64
 
Dim As Integer x, y
Input "Please enter two integers, separated by a comma : ", x , y
 
If x < y Then
Print x; " is less than "; y
End If
 
If x = y Then
Print x; " is equal to "; y
End If
 
If x > y Then
Print x; " is greater than "; y
End If
 
Print
Print "Press any key to exit"
Sleep</syntaxhighlight>
 
==={{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.
<syntaxhighlight lang="futurebasic">_window = 1
begin enum 1
_integer1Fld
_integer2Fld
_compareBtn
_messageLabel
end enum
 
local fn BuildWindow
window _window, @"Integer Comparison", (0,0,356,85)
 
textfield _integer1Fld,,, (20,44,112,21)
TextFieldSetPlaceholderString( _integer1Fld, @"Integer 1" )
 
textfield _integer2Fld,,, (140,44,112,21)
TextFieldSetPlaceholderString( _integer2Fld, @"Integer 2" )
 
button _compareBtn,,, @"Compare", (253,38,90,32)
 
textlabel _messageLabel,, (18,20,320,16)
ControlSetAlignment( _messageLabel, NSTextAlignmentCenter )
end fn
 
local fn DoDialog( ev as long, tag as long )
long int1, int2
 
select ( ev )
case _btnClick
select ( tag )
case _compareBtn
int1 = fn ControlIntegerValue( _integer1Fld )
int2 = fn ControlIntegerValue( _integer2Fld )
 
if ( int1 < int2 ) then textlabel _messageLabel, @"The first integer is less than the second integer."
if ( int1 == int2 ) then textlabel _messageLabel, @"The first integer is equal to the second integer."
if ( int1 > int2 ) then textlabel _messageLabel, @"The first integer is greater than the second integer."
 
end select
 
case _controlTextDidChange
textlabel _messageLabel, @""
end select
end fn
 
fn BuildWindow
 
on dialog fn DoDialog
 
HandleEvents</syntaxhighlight>
 
==={{header|Gambas}}===
<syntaxhighlight lang="gambas">Public Sub Form_Open()
Dim sIn As String = InputBox("Enter 2 integers seperated by a comma")
Dim iFirst, iSecond As Integer
 
iFirst = Val(Split(sIn)[0])
iSecond = Val(Split(sIn)[1])
 
If iFirst < iSecond Then Print iFirst & " is smaller than " & iSecond & gb.NewLine
If iFirst > iSecond Then Print iFirst & " is greater than " & iSecond & gb.NewLine
If iFirst = iSecond Then Print iFirst & " is equal to " & iSecond
 
End</syntaxhighlight>
Output:
<pre>
21 is greater than 18
</pre>
 
==={{header|IS-BASIC}}===
<langsyntaxhighlight ISlang="is-BASICbasic">100 INPUT PROMPT "Enter A: ":A
110 INPUT PROMPT "Enter B: ":B
120 IF A<B THEN
Line 640 ⟶ 834:
160 ELSE
170 PRINT A;"is greater than ";B
180 END IF</langsyntaxhighlight>
 
or
 
<langsyntaxhighlight ISlang="is-BASICbasic">100 INPUT PROMPT "Enter A: ":A
110 INPUT PROMPT "Enter B: ":B
120 SELECT CASE A
Line 653 ⟶ 847:
170 CASE ELSE
180 PRINT A;"is greater than ";B
190 END SELECT</langsyntaxhighlight>
 
==={{header|Liberty BASIC}}===
Verbose version:
{{works with|Just BASIC}}
<syntaxhighlight lang="lb">input "Enter an integer for a. ";a
input "Enter an integer for b. ";b
 
'a=int(a):b=int(b) ???
print "Conditional evaluation."
if a<b then print "a<b " ; a ; " < " ; b
if a=b then print "a=b " ; a ; " = " ; b
if a>b then print "a>b " ; a ; " > " ; b
 
print "Select case evaluation."
select case
case (a<b)
print "a<b " ; a ; " < " ; b
case (a=b)
print "a=b " ; a ; " = " ; b
case (a>b)
print "a>b " ; a ; " > " ; b
end select
</syntaxhighlight>
 
Concise:
<syntaxhighlight lang="lb">input "Enter an integer for a. ";a
input "Enter an integer for b. ";b
 
for i = 1 to 3
op$=word$("< = >", i)
if eval("a"+op$+"b") then print "a"+op$+"b " ; a;" ";op$;" ";b
next
</syntaxhighlight>
 
==={{header|OxygenBasic}}===
<syntaxhighlight lang="text">
uses console
print "Integer comparison. (press ctrl-c to exit) " cr cr
int n1,n2
do
print "Enter 1st integer " : n1=input
print "Enter 2nd integer " : n2=input
if n1=n2
print "number1 = number2" cr cr
elseif n1>n2
print "number1 > number2" cr cr
elseif n1<n2
print "number1 < number2" cr cr
endif
loop
</syntaxhighlight>
 
==={{header|PureBasic}}===
<syntaxhighlight lang="purebasic">If OpenConsole()
 
Print("Enter an integer: ")
x.i = Val(Input())
Print("Enter another integer: ")
y.i = Val(Input())
 
If x < y
Print( "The first integer is less than the second integer.")
ElseIf x = y
Print("The first integer is equal to the second integer.")
ElseIf x > y
Print("The first integer is greater than the second integer.")
EndIf
 
Print(#CRLF$ + #CRLF$ + "Press ENTER to exit")
Input()
CloseConsole()
EndIf</syntaxhighlight>
 
==={{header|QBasic}}===
<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 equal to "; y
IF x > y THEN PRINT x; " is greater than "; y</syntaxhighlight>
 
==={{header|Run BASIC}}===
<syntaxhighlight lang="runbasic">input "1st number:"; n1
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 greater than 2nd number";n2
if n1 = n2 then print "1st number ";n1;" is equal to 2nd number";n2</syntaxhighlight>
 
==={{header|TI-83 BASIC}}===
<syntaxhighlight lang="ti83b">Prompt A,B
If A<B: Disp "A SMALLER B"
If A>B: Disp "A GREATER B"
If A=B: Disp "A EQUAL B"</syntaxhighlight>
 
==={{header|TI-89 BASIC}}===
<syntaxhighlight lang="ti89b">Local a, b, result
Prompt a, b
If a < b Then
"<" → result
ElseIf a = b Then
"=" → result
ElseIf a > b Then
">" → result
Else
"???" → result
EndIf
Disp string(a) & " " & result & " " & string(b)</syntaxhighlight>
 
==={{Header|Tiny BASIC}}===
{{works with|TinyBasic}}
Some implementations of Tiny BASIC use <code>,</code> instead of <code>;</code> for concatenation of print items.
<syntaxhighlight lang="basic">10 REM Integer comparison
20 PRINT "Enter a number"
30 INPUT A
40 PRINT "Enter another number"
50 INPUT B
60 IF A < B THEN PRINT A;" is less than ";B
70 IF A > B THEN PRINT A;" is greater than ";B
80 IF A = B THEN PRINT A;" is equal to ";B
90 END</syntaxhighlight>
 
==={{header|True BASIC}}===
<syntaxhighlight lang="qbasic">PRINT "Please enter two integers, separated by a comma: ";
INPUT x, 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 greater than "; y
END</syntaxhighlight>
 
==={{header|VBA}}===
<syntaxhighlight lang="vb">Public Sub integer_comparison()
first_integer = CInt(InputBox("Give me an integer."))
second_integer = CInt(InputBox("Give me another integer."))
Debug.Print IIf(first_integer < second_integer, "first integer is smaller than second integer", "first integer is not smaller than 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")
End Sub</syntaxhighlight>
 
==={{header|VBScript}}===
<syntaxhighlight lang="vb">
option explicit
 
function eef( b, r1, r2 )
if b then
eef = r1
else
eef = r2
end if
end function
 
dim a, b
wscript.stdout.write "First integer: "
a = cint(wscript.stdin.readline) 'force to integer
 
wscript.stdout.write "Second integer: "
b = cint(wscript.stdin.readline) 'force to integer
 
wscript.stdout.write "First integer is "
if a < b then wscript.stdout.write "less than "
if a = b then wscript.stdout.write "equal to "
if a > b then wscript.stdout.write "greater than "
wscript.echo "Second integer."
 
wscript.stdout.write "First integer is " & _
eef( a < b, "less than ", _
eef( a = b, "equal to ", _
eef( a > b, "greater than ", vbnullstring ) ) ) & "Second integer."
</syntaxhighlight>
 
==={{header|Visual Basic .NET}}===
'''Platform:''' [[.NET]]
 
{{works with|Visual Basic .NET|9.0+}}
<syntaxhighlight lang="vbnet">Sub Main()
 
Dim a = CInt(Console.ReadLine)
Dim b = CInt(Console.ReadLine)
 
'Using if statements
If a < b Then Console.WriteLine("a is less than b")
If a = b Then Console.WriteLine("a equals b")
If a > b Then Console.WriteLine("a is greater than b")
 
'Using Case
Select Case a
Case Is < b
Console.WriteLine("a is less than b")
Case b
Console.WriteLine("a equals b")
Case Is > b
Console.WriteLine("a is greater than b")
End Select
 
End Sub</syntaxhighlight>
 
==={{header|Yabasic}}===
<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 equal to ", y : fi
if x > y then print x, " is greater than ", y : fi</syntaxhighlight>
 
==={{header|ZX Spectrum Basic}}===
<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</syntaxhighlight>
 
=={{header|Batch File}}==
<langsyntaxhighlight lang="dos">@echo off
setlocal EnableDelayedExpansion
set /p a="A: "
Line 666 ⟶ 1,066:
) else ( if %a% EQU %b% (
echo %a% is equal to %b%
)))</langsyntaxhighlight>
{{Out}}
<pre>C:\Test>IntegerComparison.bat
Line 672 ⟶ 1,072:
B: 3
5 is greater than 3</pre>
 
=={{header|BBC BASIC}}==
<lang bbcbasic> INPUT "Enter two numbers separated by a comma: " a, b
CASE TRUE OF
WHEN a < b: PRINT ;a " is less than "; b
WHEN a = b: PRINT ;a " is equal to "; b
WHEN a > b: PRINT ;a " is greater than "; b
ENDCASE</lang>
 
=={{header|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.)
<langsyntaxhighlight lang="bc">a = read()
b = read()
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 equal to b\n"
quit</langsyntaxhighlight>
 
=={{header|BCPL}}==
<syntaxhighlight lang="bcpl">get "libhdr"
 
let start() be
$( let a = ? and b = ?
writes("A? ") ; a := readn()
writes("B? ") ; b := readn()
writes(
a < b -> "A is less than B*N",
a = b -> "A is equal to B*N",
a > b -> "A is greater than B*N",
"Huh?!"
)
$)</syntaxhighlight>
 
=={{header|Befunge}}==
Line 695 ⟶ 1,103:
The branch commands (underline _ and pipe |) test for zero.
 
<langsyntaxhighlight lang="befunge">v v ">" $<
>&&"=A",,\:."=B ",,,\: .55+,-:0`|
v "<" _v#<
@,+55,," B",,,"A " < "=" <</langsyntaxhighlight>
 
=={{header|BQN}}==
The function <code>Comp</code> compares two integers and returns the appropriate string result.
 
<syntaxhighlight lang="bqn"> Comp ← ⊑·/⟜"Greater than"‿"Equal To"‿"Lesser Than"(>∾=∾<)
⊑(/⟜⟨ "Greater than" "Equal To" "Lesser Than" ⟩>∾=∾<)
4 Comp 5
"Lesser Than"
5 Comp 5
"Equal To"
6 Comp 5
"Greater than"</syntaxhighlight>
 
 
=={{header|Bracmat}}==
<langsyntaxhighlight lang="bracmat"> get$:?A
& get$:?B
& (!A:!B&out$"A equals B"|)
& (!A:<!B&out$"A is less than B"|)
& (!A:>!B&out$"A is greater than B"|);</langsyntaxhighlight>
 
=={{header|Brat}}==
<langsyntaxhighlight lang="brat">first = ask("First integer: ").to_i
second = ask("Second integer: ").to_i
 
when { first > second } { p "#{first} is greater than #{second}" }
{ first < second } { p "#{first} is less than #{second}" }
{ first == second } { p "#{first} is equal to #{second}" }</langsyntaxhighlight>
 
=={{header|Burlesque}}==
 
<langsyntaxhighlight 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
The first one is less than the second one
Line 724 ⟶ 1,146:
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
</syntaxhighlight>
</lang>
 
=={{header|C}}==
<langsyntaxhighlight lang="c">#include <stdio.h>
 
int main()
Line 744 ⟶ 1,166:
 
return 0;
}</langsyntaxhighlight>
 
=={{header|C sharp|C#}}==
<langsyntaxhighlight lang="csharp">using System;
 
class Program
Line 762 ⟶ 1,184:
Console.WriteLine("{0} is greater than {1}", a, b);
}
}</langsyntaxhighlight>
 
=={{header|C++}}==
<langsyntaxhighlight lang="cpp">#include <iostream>
 
int main()
Line 787 ⟶ 1,209:
if (a > b)
std::cout << a << " is greater than " << b << "\n";
}</langsyntaxhighlight>
 
=={{header|CFEngine}}==
<syntaxhighlight lang="cfengine3">
bundle agent __main__
{
vars:
# Change the values to test:
"first_integer" int => "10";
"second_integer" int => "9";
 
reports:
"The first integer ($(first_integer)) is less than the second integer ($(second_integer))."
if => islessthan( "$(first_integer)", "$(second_integer)" );
"The first integer ($(first_integer)) is equal to the second integer ($(second_integer))."
if => eval( "$(first_integer)==$(second_integer)", "class", "infix" );
"The first integer ($(first_integer)) is greater than the second integer ($(second_integer))."
if => isgreaterthan( "$(first_integer)", "$(second_integer)" );
}
</syntaxhighlight>
 
=={{header|ChucK}}==
<syntaxhighlight lang="text">
fun void intComparison (int one, int two)
{
Line 799 ⟶ 1,240:
// uncomment next line and change values to test
// intComparison (2,4);
</syntaxhighlight>
</lang>
 
=={{header|Clean}}==
<langsyntaxhighlight lang="clean">import StdEnv
 
compare a b
Line 813 ⟶ 1,254:
(_, a, console) = freadi console
(_, b, console) = freadi console
= compare a b</langsyntaxhighlight>
 
=={{header|Clipper}}==
<langsyntaxhighlight lang="clipper"> Function Compare(a, b)
IF a < b
? "A is less than B"
Line 825 ⟶ 1,266:
ENDIF
Return Nil
</syntaxhighlight>
</lang>
 
=={{header|Clojure}}==
Line 831 ⟶ 1,272:
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.
<langsyntaxhighlight Clojurelang="clojure">(let [[a b] (repeatedly read)]
(doseq [[op string] [[< "less than"]
[> "greater than"]
[= "equal to"]]]
(when (op a b)
(println (str a " is " string " " b)))))</langsyntaxhighlight>
 
=={{header|CMake}}==
<langsyntaxhighlight lang="cmake"># Define A and B as integers. For example:
# cmake -DA=3 -DB=5 -P compare.cmake
 
Line 857 ⟶ 1,298:
if(A GREATER B)
message(STATUS "${A} is greater than ${B}")
endif()</langsyntaxhighlight>
 
=={{header|COBOL}}==
{{works with|OpenCOBOL}}
<langsyntaxhighlight lang="cobol"> IDENTIFICATION DIVISION.
PROGRAM-ID. Int-Compare.
 
Line 886 ⟶ 1,327:
 
GOBACK
.</langsyntaxhighlight>
 
=={{header|ColdFusion}}==
Line 899 ⟶ 1,340:
===In CFML===
 
<langsyntaxhighlight lang="cfm"><cffunction name="CompareInteger">
<cfargument name="Integer1" type="numeric">
<cfargument name="Integer2" type="numeric">
Line 922 ⟶ 1,363:
</cfif>
<cfreturn VARIABLES.Result >
</cffunction></langsyntaxhighlight>
 
===In CFScript===
 
<langsyntaxhighlight lang="cfm"><cfscript>
function CompareInteger( Integer1, Integer2 ) {
VARIABLES.Result = "";
Line 949 ⟶ 1,390:
return VARIABLES.Result;
}
</cfscript></langsyntaxhighlight>
 
=={{header|Common Lisp}}==
You can type this directly into a REPL:
 
<langsyntaxhighlight lang="lisp">(let ((a (read *standard-input*))
(b (read *standard-input*)))
(cond
Line 962 ⟶ 1,403:
((> a b) (format t "~A is greater than ~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)))))</langsyntaxhighlight>
 
After hitting enter, the REPL is expecting the two numbers right away.
Line 968 ⟶ 1,409:
Alternatively, you can wrap this code in a function definition:
 
<langsyntaxhighlight lang="lisp">(defun compare-integers ()
(let ((a (read *standard-input*))
(b (read *standard-input*)))
Line 977 ⟶ 1,418:
((> a b) (format t "~A is greater than ~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)))))</langsyntaxhighlight>
 
Then, execute the function for better control:
Line 986 ⟶ 1,427:
 
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.
<langsyntaxhighlight lang="czasm">start: STP ; get input
 
x: NOP
Line 1,013 ⟶ 1,454:
JMP start
 
one: 1</langsyntaxhighlight>
 
=={{header|D}}==
<langsyntaxhighlight lang="d">void main() {
import std.stdio, std.conv, std.string;
 
Line 1,033 ⟶ 1,474:
if (a > b)
writeln(a, " is greater than ", b);
}</langsyntaxhighlight>
{{out}}
<pre>10 is less than 20</pre>
 
=={{header|Dc}}==
<langsyntaxhighlight lang="dc">[Use _ (underscore) as negative sign for numbers.]P []pP
[Enter two numbers to compare: ]P
? sbsa
Line 1,045 ⟶ 1,486:
[ [equal to]]sp lb la =p
la n [ is ]P P [ ]P lbn []pP
</syntaxhighlight>
</lang>
{{out}}
44 is greater than 3
 
=={{header|DCL}}==
<langsyntaxhighlight DCLlang="dcl">$ inquire a "Please provide an integer"
$ inquire b "Please provide another"
$ 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 .gt. b then $ write sys$output "the first integer is greater"</langsyntaxhighlight>
{{out}}
<pre>$ @integer_comparison
Line 1,072 ⟶ 1,513:
:''Slightly different than the [[#Pascal|Pascal]] example''
 
<langsyntaxhighlight Delphilang="delphi">program IntegerCompare;
 
{$APPTYPE CONSOLE}
Line 1,083 ⟶ 1,524:
if a = b then Writeln(a, ' is equal to ', b);
if a > b then Writeln(a, ' is greater than ', b);
end.</langsyntaxhighlight>
 
=={{header|Draco}}==
<syntaxhighlight lang="draco">proc nonrec main() void:
int a, b;
write("Please enter two integers: ");
read(a, b);
if a<b then writeln(a, " < ", b)
elif a=b then writeln(a, " = ", b)
elif a>b then writeln(a, " > ", b)
fi
corp</syntaxhighlight>
 
=={{header|Dyalect}}==
Line 1,089 ⟶ 1,541:
{{trans|Clipper}}
 
<langsyntaxhighlight Dyalectlang="dyalect">func compare(a, b) {
if a < b {
"A is less than B"
Line 1,097 ⟶ 1,549:
"A equals B"
}
}</langsyntaxhighlight>
 
=={{header|E}}==
<langsyntaxhighlight lang="e">def compare(a :int, b :int) {
println(if (a < b) { `$a < $b` } \
else if (a <=> b) { `$a = $b` } \
else if (a > b) { `$a > $b` } \
else { `You're calling that an integer?` })
}</langsyntaxhighlight>
 
=={{header|EasyLang}}==
<syntaxhighlight lang="text">a = number input
b = number input
if a < b
Line 1,118 ⟶ 1,570:
if a > b
print "greater"
.</langsyntaxhighlight>
 
=={{header|ECL}}==
<syntaxhighlight lang="ecl">
<lang ECL>
CompareThem(INTEGER A,INTEGER B) := FUNCTION
Result := A <=> B;
Line 1,131 ⟶ 1,583:
CompareThem(2,2); //Shows "2 is equal to 2"
CompareThem(2,1); //Shows "2 is greater than 1"
</syntaxhighlight>
</lang>
 
=={{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.
<langsyntaxhighlight lang="edsac">[ Integer comparison
==================
Line 1,189 ⟶ 1,641:
[ 18 ] AF [ - character ]
EZPF [ begin execution ]</langsyntaxhighlight>
 
=={{header|Efene}}==
Line 1,195 ⟶ 1,647:
since if does pattern matching the else is required to avoid the application from crashing
 
<langsyntaxhighlight lang="efene">compare = fn (A, B) {
if A == B {
io.format("~p equals ~p~n", [A, B])
Line 1,224 ⟶ 1,676:
compare(4, 5)
}
</syntaxhighlight>
</lang>
 
=={{header|Eiffel}}==
<langsyntaxhighlight Eiffellang="eiffel">class
APPLICATION
inherit
Line 1,256 ⟶ 1,708:
end
end
end</langsyntaxhighlight>
 
=={{header|Elena}}==
ELENA 4.x:
<langsyntaxhighlight lang="elena">import extensions;
public program()
Line 1,275 ⟶ 1,727:
if (a > b)
{ console.printLine(a," is greater than ",b) }
}</langsyntaxhighlight>
 
=={{header|Elixir}}==
<langsyntaxhighlight ELixirlang="elixir">{a,_} = IO.gets("Enter your first integer: ") |> Integer.parse
{b,_} = IO.gets("Enter your second integer: ") |> Integer.parse
 
Line 1,288 ⟶ 1,740:
a == b ->
IO.puts "#{a} is equal to #{b}"
end</langsyntaxhighlight>
 
=={{header|Emacs Lisp}}==
<lang Emacs Lisp>
(progn
(if (< 1 2) (insert "True\n") (insert "False\n") )
(if (= 1 2) (insert "True\n") (insert "False\n") )
(if (= 1 1) (insert "True\n") (insert "False\n") )
(if (> 1 2) (insert "True\n") (insert "False\n") )
(if (<= 1 2) (insert "True\n") (insert "False\n") )
(if (>= 1 2) (insert "True\n") (insert "False\n") ))
</lang>
<b>Output:</b>
<pre>
True
False
True
False
True
False
</pre>
 
<syntaxhighlight lang="lisp">(defun integer-comparison (a b)
… or …
 
<lang Emacs Lisp>
(defun integer-comparison (a b)
"Compare A to B and print the outcome in the message buffer."
(interactive "nFirst integer ⇒\nnSecond integer ⇒")
Line 1,319 ⟶ 1,750:
((< 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 equal to %d." a b))))</syntaxhighlight>
</lang>
 
Invoke from within Emacs Lisp (or ege.g., with <code>M-:</code>) as <lang Emacs Lispcode>(integer-comparison 12 42)</langcode>
Or, use <code>M-x integer-comparison <RET</code> and you'll be prompted for the two numbers.
 
=={{header|EMal}}==
<syntaxhighlight lang="emal">
fun main = int by List args
int a, b
if args.length > 1
a = int!args[0]
b = int!args[1]
else
a = ask(int, "Enter the first integer ")
b = ask(int, "Enter the second integer ")
end
writeLine("=== a <> b is " + (a <> b) + " ===")
if a < b do writeLine(a + " < " + b) end
if a == b do writeLine(a + " == " + b) end
if a > b do writeLine(a + " > " + b) end
return 0
end
exit main(Runtime.args)
</syntaxhighlight>
{{out}}
<pre>
emal.exe Org\RosettaCode\IntegerComparison.emal
Enter the first integer 42
Enter the second integer 64
=== a <> b is -1 ===
42 < 64
</pre>
 
=={{header|Erlang}}==
<langsyntaxhighlight lang="erlang">
main() ->
{ok, [N]} = io:fread("First integer: ", "~d"),
Line 1,345 ⟶ 1,803:
end.
 
</syntaxhighlight>
</lang>
 
=={{header|Euphoria}}==
<langsyntaxhighlight Euphorialang="euphoria">include get.e
 
integer a,b
Line 1,362 ⟶ 1,820:
puts(1,"grater then")
end if
puts(1," b")</langsyntaxhighlight>
 
=={{header|Excel}}==
Line 1,368 ⟶ 1,826:
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:
 
<langsyntaxhighlight 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)))
</syntaxhighlight>
</lang>
 
In a Google Docs spreadsheet, that becomes :
 
<langsyntaxhighlight 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)))
</syntaxhighlight>
</lang>
 
=={{header|F_Sharp|F#}}==
<langsyntaxhighlight lang="fsharp">let compare_ints a b =
let r =
match a with
Line 1,386 ⟶ 1,844:
| x when x > b -> 1, printfn "%d is greater than %d" x b
| x -> 0, printf "default condition (not reached)"
fst r</langsyntaxhighlight>
 
=={{header|Factor}}==
<langsyntaxhighlight lang="factor">: example ( -- )
readln readln [ string>number ] bi@
[ > [ "A > B" print ] when ]
[ < [ "A < B" print ] when ]
[ = [ "A = B" print ] when ] 2tri ;
</syntaxhighlight>
</lang>
 
=={{header|FALSE}}==
Only equals and greater than are available.
<langsyntaxhighlight lang="false">^^ \$@$@$@$@\
>[\$," is greater than "\$,]?
\>[\$," is less than "\$,]?
=["characters are equal"]?</langsyntaxhighlight>
 
=={{header|Fantom}}==
Line 1,407 ⟶ 1,865:
Uses Env.cur to access stdin and stdout.
 
<langsyntaxhighlight lang="fantom">class Main
{
public static Void main ()
Line 1,429 ⟶ 1,887:
}
}
</syntaxhighlight>
</lang>
 
=={{header|Fermat}}==
<syntaxhighlight lang="fermat">Func Compare =
?a;
?b;
if a=b then !'Equal' fi;
if a<b then !'Less than' fi;
if a>b then !'Greater than' fi;
.;</syntaxhighlight>
 
=={{header|Fish}}==
This example assumes you [http://www.esolangs.org/wiki/Fish#Input.2Foutput pre-populate] the stack with the two integers.
<langsyntaxhighlight Fishlang="fish">l2=?vv ~< v o<
v <>l?^"Please pre-populate the stack with the two integers."ar>l?^;
\$:@@:@)?v v ;oanv!!!?<
Line 1,445 ⟶ 1,912:
> v
/oo". "nooooo" and "n$< v o<
>"They're not equal, not greater than and not smaller than eachother... strange."ar>l?^;</langsyntaxhighlight>
 
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,452 ⟶ 1,919:
 
To keep the example simple, the word takes the two numbers from the stack.
<langsyntaxhighlight lang="forth">: compare-integers ( a b -- )
2dup < if ." a is less than b" then
2dup > if ." a is greater than b" then
= if ." a is equal to b" then ;</langsyntaxhighlight>
 
=={{header|Fortran}}==
In ALL Fortran versions (including original 1950's era) you could use an "arithmetic IF" statement to compare using subtraction:
<langsyntaxhighlight lang="fortran">program arithif
integer a, b
 
Line 1,475 ⟶ 1,942:
40 continue
 
end</langsyntaxhighlight>
 
In ANSI FORTRAN 66 or later you could use relational operators (.lt., .gt., .eq., etc.) and unstructured IF statements:
<langsyntaxhighlight lang="fortran">program compare
integer a, b
c fortran 77 I/O statements, for simplicity
Line 1,486 ⟶ 1,953:
if (a .eq. b) write(*, *) a, ' is equal to ', b
if (a .gt. b) write(*, *) a, ' is greater than ', b
end</langsyntaxhighlight>
 
In ANSI FORTRAN 77 or later you can use relational operators and structured IF statements:
<langsyntaxhighlight lang="fortran">program compare
integer a, b
read(*,*) a, b
Line 1,501 ⟶ 1,968:
end if
 
end</langsyntaxhighlight>
 
In ISO Fortran 90 or later you can use symbolic relational operators (<, >, ==, etc.)
<langsyntaxhighlight lang="fortran">program compare
integer :: a, b
read(*,*) a, b
Line 1,516 ⟶ 1,983:
end if
 
end program compare</langsyntaxhighlight>
 
=={{header|FreeBASIC}}==
<lang freebasic>' FB 1.05.0 Win64
 
Dim As Integer x, y
Input "Please enter two integers, separated by a comma : ", x , y
 
If x < y Then
Print x; " is less than "; y
End If
 
If x = y Then
Print x; " is equal to "; y
End If
 
If x > y Then
Print x; " is greater than "; y
End If
 
Print
Print "Press any key to exit"
Sleep</lang>
 
=={{header|friendly interactive shell}}==
<langsyntaxhighlight lang="fishshell">read a
read b
 
Line 1,550 ⟶ 1,995:
else if test $a -eq $b
echo Equal
end</langsyntaxhighlight>
 
=={{header|Frink}}==
All integers in Frink can be arbitrarily large.
 
<syntaxhighlight lang="frink">[a,b] = eval[input["Enter numbers",["a","b"]]]
<lang frink>
[a,b] = eval[input["Enter numbers",["a","b"]]]
if a<b
println["$a < $b"]
Line 1,562 ⟶ 2,006:
println["$a == $b"]
if a>b
println["$a > $b"]</syntaxhighlight>
</lang>
 
=={{header|FunL}}==
<langsyntaxhighlight lang="funl">import console.readInt
 
a = readInt()
Line 1,573 ⟶ 2,016:
val (_, c) = [((<), 'less than'), ((==), 'equal to'), ((>), 'greater than')].find( (compare, _) -> compare(a, b) ).get()
 
println( "$a is $c $b." )</langsyntaxhighlight>
 
=={{header|FutureBasicFōrmulæ}}==
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>
include "ConsoleWindow"
 
{{FormulaeEntry|page=https://formulae.org/?script=examples/Integer_comparison}}
dim as long n1, n2
 
'''Solution'''
input "Enter two numbers (separated by a comma) to compare: "; n1, n2
 
Fōrmulæ has an intrinsic expression for [[wp:Three-way_comparison|three-way comparison]] that works for integers and other types (decimal and rational numbers, strings, time expressions, etc). It returns expressions that flag one of the three possible results.
if n1 < n2 then print : print n1; " is less than"; n2
if n1 > n2 then print : print n1; " is greater than"; n2
if n1 == n2 then print : print n1; " equals"; n2
</lang>
 
[[File:Fōrmulæ - Integer comparison 01.png]]
=={{header|Gambas}}==
<lang gambas>Public Sub Form_Open()
Dim sIn As String = InputBox("Enter 2 integers seperated by a comma")
Dim iFirst, iSecond As Integer
 
[[File:Fōrmulæ - Integer comparison 02.png]]
iFirst = Val(Split(sIn)[0])
iSecond = Val(Split(sIn)[1])
 
However, a simple function can be written for the requirement:
If iFirst < iSecond Then Print iFirst & " is smaller than " & iSecond & gb.NewLine
If iFirst > iSecond Then Print iFirst & " is greater than " & iSecond & gb.NewLine
If iFirst = iSecond Then Print iFirst & " is equal to " & iSecond
 
[[File:Fōrmulæ - Integer comparison 03.png]]
End</lang>
 
Output:
[[File:Fōrmulæ - Integer comparison 04.png]]
<pre>
 
21 is greater than 18
[[File:Fōrmulæ - Integer comparison 05.png]]
</pre>
 
=={{header|Go}}==
<langsyntaxhighlight lang="go">package main
 
import (
Line 1,633 ⟶ 2,064:
fmt.Println(n1, "greater than", n2)
}
}</langsyntaxhighlight>
 
=={{header|Groovy}}==
 
===Relational Operators===
<langsyntaxhighlight lang="groovy">def comparison = { a, b ->
println "a ? b = ${a} ? ${b} = a ${a < b ? '<' : a > b ? '>' : a == b ? '==' : '?'} b"
}</langsyntaxhighlight>
 
Program:
<langsyntaxhighlight lang="groovy">comparison(2000,3)
comparison(2000,300000)
comparison(2000,2000)</langsyntaxhighlight>
 
{{out}}
Line 1,654 ⟶ 2,085:
==="Spaceship" (compareTo) Operator===
Using spaceship operator and a lookup table:
<langsyntaxhighlight lang="groovy">final rels = [ (-1) : '<', 0 : '==', 1 : '>' ].asImmutable()
def comparisonSpaceship = { a, b ->
println "a ? b = ${a} ? ${b} = a ${rels[a <=> b]} b"
}</langsyntaxhighlight>
 
Program:
<langsyntaxhighlight lang="groovy">comparison(2000,3)
comparison(2000,300000)
comparison(2000,2000)</langsyntaxhighlight>
 
{{out}}
Line 1,670 ⟶ 2,101:
 
=={{header|Harbour}}==
<langsyntaxhighlight lang="visualfoxpro">PROCEDURE Compare( a, b )
 
IF a < b
Line 1,680 ⟶ 2,111:
ENDIF
 
RETURN</langsyntaxhighlight>
 
=={{header|Haskell}}==
<langsyntaxhighlight lang="haskell">myCompare :: Integer -> Integer -> String
myCompare a b
| a < b = "A is less than B"
Line 1,692 ⟶ 2,123:
a <- readLn
b <- readLn
putStrLn $ myCompare a b</langsyntaxhighlight>
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:
<langsyntaxhighlight lang="haskell">myCompare a b = case compare a b of
LT -> "A is less than B"
GT -> "A is greater than B"
EQ -> "A equals B"</langsyntaxhighlight>
 
=={{header|hexiscript}}==
<langsyntaxhighlight lang="hexiscript">let a scan int
let b scan int
 
Line 1,713 ⟶ 2,144:
if a = b
println a + " is equal to " + b
endif</langsyntaxhighlight>
 
=={{header|HicEst}}==
<langsyntaxhighlight lang="hicest">DLG(NameEdit=a, NameEdit=b, Button='OK')
IF (a < b) THEN
Line 1,724 ⟶ 2,155:
ELSEIF(a > b) THEN
WRITE(Messagebox) a, ' is greater than ', b
ENDIF</langsyntaxhighlight>
 
=={{header|HolyC}}==
<langsyntaxhighlight lang="holyc">I64 *a, *b;
a = Str2I64(GetStr("Enter your first number: "));
b = Str2I64(GetStr("Enter your second number: "));
Line 1,738 ⟶ 2,169:
 
if (a > b)
Print("%d is greater than %d\n", a, b);</langsyntaxhighlight>
 
=={{header|Hy}}==
<langsyntaxhighlight lang="clojure">(def a (int (input "Enter value of a: ")))
(def b (int (input "Enter value of b: ")))
 
(print (cond [(< a b) "a is less than b"]
[(> a b) "a is greater than b"]
[(= a b) "a is equal to b"]))</langsyntaxhighlight>
 
=={{header|i}}==
<langsyntaxhighlight lang="i">software {
a = number(read(' '))
b = number(read())
Line 1,764 ⟶ 2,195:
print(a, " is greater than ", b)
end
}</langsyntaxhighlight>
 
=={{header|Icon}} and {{header|Unicon}}==
<langsyntaxhighlight Iconlang="icon">procedure main()
 
until integer(a) do {
Line 1,782 ⟶ 2,213:
write(a," = ", a = b)
write(a," > ", a > b)
end</langsyntaxhighlight>
 
{{out}}
Line 1,792 ⟶ 2,223:
=={{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>:
<langsyntaxhighlight lang="j">compare=: < , = , >
 
cti=: dyad define
Line 1,798 ⟶ 2,229:
English =. ' is less than ';' is equal to ';' is greater than '
x (":@[, (compare select English"_), ":@]) y
)</langsyntaxhighlight>
Examples of use:
<langsyntaxhighlight lang="j"> 4 compare 4
0 1 0
4 cti 3
4 is greater than 3</langsyntaxhighlight>
 
=={{header|Java}}==
<langsyntaxhighlight lang="java">import java.io.*;
 
public class compInt {
Line 1,826 ⟶ 2,257:
} catch(IOException e) { }
}
}</langsyntaxhighlight>
 
=={{header|JavaScript}}==
<langsyntaxhighlight lang="javascript">
// Using type coercion
function compare(a, b) {
Line 1,856 ⟶ 2,287:
}
}
</syntaxhighlight>
</lang>
 
=={{header|Joy}}==
<langsyntaxhighlight lang="joy">#!/usr/local/bin/joy.exe
DEFINE
prompt == "Please enter a number and <Enter>: " putchars;
Line 1,865 ⟶ 2,296:
putln == put newline.
 
stdin # F
prompt fgets # S F
10 strtol # A F
swap # F A
dupd # F A A
prompt fgets # S F A A
10 strtol # B F A A
popd # B A A
dup # B B A A
rollup # B A B A
[<] [swap put "is less than " putchars putln] [] ifte
[=] [swap put "is equal to " putchars putln] [] ifte
[>] [swap put "is greater than " putchars putln] [] ifte
# B A
quit.</langsyntaxhighlight>
 
=={{header|jq}}==
<langsyntaxhighlight lang="jq"># compare/0 compares the first two items if they are numbers,
# otherwise an "uncomparable" message is emitted.
 
Line 1,897 ⟶ 2,328:
end ;
 
compare</langsyntaxhighlight>
 
Examples;
<syntaxhighlight lang="jq">
<lang jq>
$ jq -s -r -f Integer_comparison.jq
1 2
Line 1,908 ⟶ 2,339:
1 "a"
1 is uncomparable to a
</syntaxhighlight>
</lang>
 
=={{header|Julia}}==
<langsyntaxhighlight Julialang="julia">function compare()
int1 = readline(stdin)
int2 = readline(stdin)
Line 1,921 ⟶ 2,352:
int2)
end
</langsyntaxhighlight>{{out}}
<pre>julia> compare()
3
Line 1,929 ⟶ 2,360:
 
=={{header|Kotlin}}==
<syntaxhighlight lang scala="kotlin">fun main(args: Array<String>) {
val n1 = readLine()!!.toLong()
val n2 = readLine()!!.toLong()
Line 1,938 ⟶ 2,369:
else -> ""
})
}</langsyntaxhighlight>
 
=={{header|Lambdatalk}}==
<syntaxhighlight lang="scheme">
<lang Scheme>
{def compare
{lambda {:a :b}
Line 1,958 ⟶ 2,389:
{compare 1 1}
-> 1 is equal to 1
</syntaxhighlight>
</lang>
 
=={{header|Lang}}==
<syntaxhighlight lang="lang">
fn.print(Enter a:\s)
$a = fn.int(fn.input())
 
fn.print(Enter b:\s)
$b = fn.int(fn.input())
 
if($a < $b) {
fn.println($a is less than $b)
}elif($a > $b) {
fn.println($a is greater than $b)
}elif($a === $b) {
fn.println($a is equals to $b)
}
</syntaxhighlight>
 
=={{header|Lasso}}==
<langsyntaxhighlight Lassolang="lasso">local(
number1 = integer(web_request -> param('number1')),
number2 = integer(web_request -> param('number2'))
Line 1,970 ⟶ 2,418:
#number1 == #number2 ? 'Number 1 is the same as Number 2' | 'Number 1 is not the same as Number 2'
'<br />'
#number1 > #number2 ? 'Number 1 is greater than Number 2' | 'Number 1 is not greater than Number 2'</langsyntaxhighlight>
 
{{out}}
Line 1,977 ⟶ 2,425:
Number 1 is the same as Number 2
Number 1 is not greater than Number 2</pre>
 
=={{header|Liberty BASIC}}==
Verbose version:
<lang lb>input "Enter an integer for a. ";a
input "Enter an integer for b. ";b
 
'a=int(a):b=int(b) ???
print "Conditional evaluation."
if a<b then print "a<b " ; a ; " < " ; b
if a=b then print "a=b " ; a ; " = " ; b
if a>b then print "a>b " ; a ; " > " ; b
 
print "Select case evaluation."
select case
case (a<b)
print "a<b " ; a ; " < " ; b
case (a=b)
print "a=b " ; a ; " = " ; b
case (a>b)
print "a>b " ; a ; " > " ; b
end select
</lang>
 
Concise:
<lang lb>input "Enter an integer for a. ";a
input "Enter an integer for b. ";b
 
for i = 1 to 3
op$=word$("< = >", i)
if eval("a"+op$+"b") then print "a"+op$+"b " ; a;" ";op$;" ";b
next
</lang>
 
=={{header|LIL}}==
<langsyntaxhighlight lang="tcl">print "Enter two numbers separated by space"
set rc [readline]
set a [index $rc 0]
Line 2,019 ⟶ 2,434:
if {$a < $b} {print "$a is less than $b"}
if {$a == $b} {print "$a is equal to $b"}
if {$a > $b} {print "$a is greater than $b"}</langsyntaxhighlight>
 
=={{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:
<langsyntaxhighlight lang="lingo">on compare (a, 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 greater than "&b
end</langsyntaxhighlight>
 
=={{header|LiveCode}}==
<langsyntaxhighlight LiveCodelang="livecode">ask question "Enter 2 numbers (comma separated)" with empty titled "Enter 2 numbers"
if it is not empty then
put item 1 of it into num1
Line 2,049 ⟶ 2,464:
end switch
end if
end if</langsyntaxhighlight>
 
=={{header|LLVM}}==
Line 2,056 ⟶ 2,471:
{{libheader|cstdlib}}
 
<langsyntaxhighlight lang="llvm">; ModuleID = 'test.o'
;e means little endian
;p: { pointer size : pointer abi : preferred alignment for pointers }
Line 2,147 ⟶ 2,562:
 
declare i32 @printf(i8* nocapture, ...) nounwind
</syntaxhighlight>
</lang>
 
=={{header|Logo}}==
<langsyntaxhighlight lang="logo">to compare :a :b
if :a = :b [(print :a [equals] :b)]
if :a < :b [(print :a [is less than] :b)]
if :a > :b [(print :a [is greater than] :b)]
end</langsyntaxhighlight>
Each infix operator has prefix synonyms (equalp, equal?, lessp, less?, greaterp, greater?), where the 'p' stands for "predicate" as in [[Lisp]].
 
Line 2,161 ⟶ 2,576:
 
==={{header|avec SI}}===
<langsyntaxhighlight LSElang="lse">(* Comparaison de deux entiers en LSE (LSE-2000) *)
ENTIER A, B
LIRE ['Entrez un premier entier:',U] A
Line 2,173 ⟶ 2,588:
SI A > B ALORS
AFFICHER [U,' est plus grand que ',U,/] A, B
FIN SI</langsyntaxhighlight>
 
==={{header|avec ÉVALUER}}===
<langsyntaxhighlight LSElang="lse">(* Comparaison de deux entiers en LSE (LSE-2000) *)
ENTIER A, B
LIRE ['Entrez un premier entier:',U] A
Line 2,187 ⟶ 2,602:
QUAND AUTRE
AFFICHER [U,' est plus grand que ',U,/] A, B
FIN EVALUER</langsyntaxhighlight>
 
==={{header|avec SI..IS}}===
<langsyntaxhighlight LSElang="lse">(* Comparaison de deux entiers en LSE (LSE-2000) *)
ENTIER A, B
LIRE ['Entrez un premier entier:',U] A
Line 2,198 ⟶ 2,613:
SI A = B ALORS ' est égale à ' SINON \
SI A > B ALORS ' est plus grand que ' SINON '?' IS IS IS, B
</syntaxhighlight>
</lang>
 
=={{header|LSE64}}==
<langsyntaxhighlight lang="lse64">over : 2 pick
2dup : over over
 
Line 2,208 ⟶ 2,623:
compare : 2dup > then " is more than"
 
show : compare rot , sp ,t sp , nl</langsyntaxhighlight>
 
=={{header|Lua}}==
<langsyntaxhighlight lang="lua">print('Enter the first number: ')
a = tonumber(io.stdin:read())
print('Enter the second number: ')
Line 2,218 ⟶ 2,633:
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 equal to " .. b) end</langsyntaxhighlight>
 
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:
 
<langsyntaxhighlight lang="lua">-- if a = b then print("This will not work")</langsyntaxhighlight>
 
=={{header|Maple}}==
<langsyntaxhighlight Maplelang="maple">CompareNumbers := proc( )
local a, b;
printf( "Enter a number:> " );
Line 2,240 ⟶ 2,655:
end proc:
 
CompareNumbers();</langsyntaxhighlight>
 
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<langsyntaxhighlight Mathematicalang="mathematica">a=Input["Give me the value for a please!"];
b=Input["Give me the value for b please!"];
If[a==b,Print["a equals b"]]
If[a>b,Print["a is bigger than b"]]
If[a<b,Print["b is bigger than a"]]</langsyntaxhighlight>
 
=={{header|Maxima}}==
<langsyntaxhighlight lang="maxima">/* all 6 comparison operators (last is "not equal") */
block(
[a: read("a?"), b: read("b?")],
Line 2,258 ⟶ 2,673:
if a >= b then print(a, ">=", b),
if a = b then print(a, "=", b),
if a # b then print(a, "#", b))$</langsyntaxhighlight>
 
=={{header|MAXScript}}==
<langsyntaxhighlight lang="maxscript">a = getKBValue prompt:"Enter value of a:"
b = getKBValue prompt:"Enter value of 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 equal to b"</langsyntaxhighlight>
 
=={{header|Metafont}}==
<langsyntaxhighlight lang="metafont">message "integer 1: ";
a1 := scantokens readstring;
message "integer 2: ";
Line 2,279 ⟶ 2,694:
message decimal a1 & " is equal to " & decimal a2
fi;
end</langsyntaxhighlight>
 
=={{header|min}}==
{{works with|min|0.19.3}}
<langsyntaxhighlight lang="min">"$1 is $2 $3."
("Enter an integer" ask) 2 times over over
(
Line 2,290 ⟶ 2,705:
((==) ("equal to"))
) case
' append prepend % print</langsyntaxhighlight>
 
=={{header|MiniScript}}==
<langsyntaxhighlight MiniScriptlang="miniscript">integer1 = input("Please Input Integer 1:").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 equal to " + integer2
if integer1 > integer2 then print integer1 + " is greater than " + integer2</langsyntaxhighlight>
 
=={{header|МК-61/52}}==
<syntaxhighlight lang="text">- ЗН С/П</langsyntaxhighlight>
 
''Input:'' a ^ b
Line 2,310 ⟶ 2,725:
Note that ML/I only has tests for ''equality'', ''greater-than'', and ''greater-than-or-equal''.
 
<langsyntaxhighlight MLlang="ml/Ii">"" Integer comparison
"" assumes macros on input stream 1, terminal on stream 2
MCSKIP MT,<>
Line 2,327 ⟶ 2,742:
>
MCSET S1=1
~MCSET S10=2</langsyntaxhighlight>
 
=={{header|MMIX}}==
Some simple error checking is included.
<langsyntaxhighlight lang="mmix">// main registers
p IS $255 % pointer
pp GREG % backup for p
Line 2,415 ⟶ 2,830:
LDA p,GT % _ : print 'GT'
2H TRAP 0,Fputs,StdOut % print result
TRAP 0,Halt,0</langsyntaxhighlight>
Example of use:
<pre>~/MIX/MMIX/Progs> mmix compare2ints 121 122
Line 2,436 ⟶ 2,851:
 
=={{header|Modula-2}}==
<langsyntaxhighlight lang="modula2">MODULE IntCompare;
 
IMPORT InOut;
Line 2,457 ⟶ 2,872:
InOut.WriteInt(B, 1);
InOut.WriteLn
END IntCompare.</langsyntaxhighlight>
 
=={{header|Modula-3}}==
<langsyntaxhighlight lang="modula3">MODULE Main;
 
FROM IO IMPORT Put, GetInt;
Line 2,477 ⟶ 2,892:
Put(Int(a) & " is greater than " & Int(b) & "\n");
END;
END Main.</langsyntaxhighlight>
 
=={{header|MUMPS}}==
<syntaxhighlight lang="text">INTCOMP
NEW A,B
INTCOMPREAD
Line 2,490 ⟶ 2,905:
IF A>B WRITE !,A," is greater than ",B
KILL A,B
QUIT</langsyntaxhighlight>
{{out}}
<pre>USER>d INTCOMP^ROSETTA
Line 2,509 ⟶ 2,924:
 
=={{header|Nanoquery}}==
<langsyntaxhighlight Nanoquerylang="nanoquery">print "enter first integer: "
first = int(input())
print "enter second integer: "
Line 2,520 ⟶ 2,935:
else if first > second
println first + " is greater than " + second
end</langsyntaxhighlight>
 
=={{header|Nemerle}}==
Showing both the use of comparison operators and the .Net Int32.CompareTo() method.
<langsyntaxhighlight Nemerlelang="nemerle">using System;
using System.Console;
 
Line 2,554 ⟶ 2,969:
}
}
}</langsyntaxhighlight>
 
=={{header|NetRexx}}==
<langsyntaxhighlight NetRexxlang="netrexx">/* NetRexx */
options replace format comments java crossref symbols nobinary
 
Line 2,572 ⟶ 2,987:
 
return
</syntaxhighlight>
</lang>
 
=={{header|NewLISP}}==
<syntaxhighlight lang="newlisp">
<lang NewLISP>
(print "Please enter the first number: ")
(set 'A (int (read-line)))
Line 2,587 ⟶ 3,002:
(true "less than"))
" the second.")
</syntaxhighlight>
</lang>
 
=={{header|Nim}}==
<langsyntaxhighlight lang="nim">import rdstdin, strutils
var a = parseInt(readLineFromStdin "Enter value of a: ")
var b = parseInt(readLineFromStdin "Enter value of b: ")
Line 2,599 ⟶ 3,014:
echo "a is greater than b"
elif a == b:
echo "a is equal to b"</langsyntaxhighlight>
 
=={{header|NSIS}}==
===Pure NSIS (Using [http://nsis.sourceforge.net/Docs/Chapter4.html#4.9.4.13 IntCmp] directly)===
<langsyntaxhighlight lang="nsis">
Function IntergerComparison
Push $0
Line 2,626 ⟶ 3,041:
Pop $0
FunctionEnd
</syntaxhighlight>
</lang>
=== Using [http://nsis.sourceforge.net/LogicLib LogicLib] (bundled library) ===
{{libheader|LogicLib}}
<langsyntaxhighlight lang="nsis">
Function IntegerComparison
Push $0
Line 2,648 ⟶ 3,063:
Pop $0
FunctionEnd
</syntaxhighlight>
</lang>
 
=={{header|Nu}}==
<syntaxhighlight lang="nu">
[First Second] | each {input $"($in) integer: "| into int} | [
[($in.0 < $in.1) "less than"]
[($in.0 == $in.1) "equal to"]
[($in.0 > $in.1) "greater than"]
] | each {if $in.0 {$"The first integer is ($in.1) the second integer."}} | str join "\n"
</syntaxhighlight>
 
=={{header|Oberon-2}}==
<langsyntaxhighlight lang="oberon2">MODULE Compare;
 
IMPORT In, Out;
Line 2,676 ⟶ 3,100:
Out.Ln;
END;
END Compare.</langsyntaxhighlight>
 
=={{header|Objeck}}==
<langsyntaxhighlight lang="objeck">
bundle Default {
class IntCompare {
Line 2,700 ⟶ 3,124:
}
}
</syntaxhighlight>
</lang>
 
=={{header|OCaml}}==
<langsyntaxhighlight lang="ocaml">let my_compare a b =
if a < b then "A is less than B"
else if a > b then "A is greater than B"
Line 2,712 ⟶ 3,136:
let a = read_int ()
and b = read_int () in
print_endline (my_compare a b)</langsyntaxhighlight>
 
=={{header|Octave}}==
<langsyntaxhighlight lang="octave">printf("Enter a: ");
a = scanf("%d", "C");
printf("Enter b: ");
Line 2,725 ⟶ 3,149:
elseif (a < b)
disp("a less than b");
endif</langsyntaxhighlight>
 
=={{header|Oforth}}==
 
<langsyntaxhighlight Oforthlang="oforth">import: console
 
: cmpInt
Line 2,738 ⟶ 3,162:
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 greater than " << b << cr ] ;</langsyntaxhighlight>
 
=={{header|Ol}}==
<langsyntaxhighlight lang="scheme">
(define (compare a b)
(cond ((< a b) "A is less than B")
Line 2,758 ⟶ 3,182:
; manual user input:
(print (compare (read) (read)))
</syntaxhighlight>
</lang>
 
=={{header|Oz}}==
<langsyntaxhighlight lang="oz">functor
import
Application(exit)
Line 2,788 ⟶ 3,212:
 
{Application.exit 0}
end</langsyntaxhighlight>
 
=={{header|PARI/GP}}==
<langsyntaxhighlight lang="parigp">a=input();
b=input();
if(a<b, print(a" < "b));
if(a==b, print(a" = "b));
if(a>b, print(a" > "b));</langsyntaxhighlight>
 
=={{header|Pascal}}==
<langsyntaxhighlight lang="pascal">program compare(input, output);
 
var
Line 2,811 ⟶ 3,235:
if (a = b) then writeln(a, ' is equal to ', b);
if (a > b) then writeln(a, ' is greater than ', b);
end.</langsyntaxhighlight>
 
=={{header|Perl}}==
Line 2,818 ⟶ 3,242:
Separate tests for less than, greater than, and equals
 
<langsyntaxhighlight lang="perl">sub test_num {
my $f = shift;
my $s = shift;
Line 2,830 ⟶ 3,254:
return 0; # returns 0 $f is equal to $s
};
};</langsyntaxhighlight>
 
All three tests in one. If $f is less than $s return -1, greater than return 1, equal to return 0
 
<langsyntaxhighlight lang="perl">sub test_num {
return $_[0] <=> $_[1];
};</langsyntaxhighlight>
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.
 
<langsyntaxhighlight lang="perl"># Get input, test and display
print "Enter two integers: ";
($x, $y) = split ' ', <>;
print $x, (" is less than ", " is equal to ",
" is greater than ")[test_num($x, $y) + 1], $y, "\n";</langsyntaxhighlight>
 
=={{header|Phix}}==
{{libheader|Phix/basics}}
<lang Phix>atom a = prompt_number("first number:",{}),
<!--<syntaxhighlight lang="phix">-->
b = prompt_number("second number:",{})
<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>
printf(1,"%g is ",a)
if a < b then
<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 is "</span><span style="color: #0000FF;">,</span><span style="color: #000000;">a</span><span style="color: #0000FF;">)</span>
puts(1,"less than")
<span style="color: #008080;">if</span> <span style="color: #000000;">a</span> <span style="color: #0000FF;"><</span> <span style="color: #000000;">b</span> <span style="color: #008080;">then</span>
elsif a = b then
<span style="color: #7060A8;">puts</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"less than"</span><span style="color: #0000FF;">)</span>
puts(1,"equal to")
<span style="color: #008080;">elsif</span> <span style="color: #000000;">a</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">b</span> <span style="color: #008080;">then</span>
elsif a > b then
<span style="color: #7060A8;">puts</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"equal to"</span><span style="color: #0000FF;">)</span>
puts(1,"greater than")
<span style="color: #008080;">elsif</span> <span style="color: #000000;">a</span> <span style="color: #0000FF;">></span> <span style="color: #000000;">b</span> <span style="color: #008080;">then</span>
end if
<span style="color: #7060A8;">puts</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"greater than"</span><span style="color: #0000FF;">)</span>
printf(1," %g",b)</lang>
<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>
<!--</syntaxhighlight>-->
 
=={{header|Phixmonti}}==
<syntaxhighlight lang="Phixmonti">/# Rosetta Code problem: http://rosettacode.org/wiki/Integer_comparison
by Galileo, 10/2022 #/
 
"Enter first number: " input tonum nl
"Enter second number: " input tonum nl
 
over over -
rot print " is " print
/# dup 0 < if drop "less" else 0 > if "greater" else "equal" endif endif #/
dup 0 < if drop "less" else dup 0 > if drop "greater" else dup 0 == if drop "equal" endif endif endif
print " than " print print
</syntaxhighlight>
{{out}}
<pre>Enter first number: 5
Enter second number: 1
5 is greater than 1
=== Press any key to exit ===</pre>
 
=={{header|PHL}}==
 
<langsyntaxhighlight lang="phl">module intergertest;
 
extern printf;
Line 2,881 ⟶ 3,327:
return 0;
]</langsyntaxhighlight>
 
=={{header|PHP}}==
<langsyntaxhighlight lang="php"><?php
 
echo "Enter an integer [int1]: ";
Line 2,910 ⟶ 3,356:
echo "int1 > int2\n";
 
?></langsyntaxhighlight>
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}}==
<langsyntaxhighlight PicoLisplang="picolisp">(prin "Please enter two values: ")
 
(in NIL # Read from standard input
Line 2,924 ⟶ 3,370:
((= A B) "equal to")
(T "less than") )
" the second." ) ) )</langsyntaxhighlight>
{{out}}
<pre>Please enter two values: 4 3
Line 2,930 ⟶ 3,376:
 
=={{header|Pike}}==
<langsyntaxhighlight lang="pike">int main(int argc, array(int) argv){
if(argc != 3){
write("usage: `pike compare-two-ints.pike <x> <y>` where x and y are integers.\n");
Line 2,946 ⟶ 3,392:
write(a + " is equal to " + b + "\n");
}
}</langsyntaxhighlight>
 
=={{header|PL/I}}==
<syntaxhighlight lang="pl/i">
<lang PL/I>
declare (a, b) fixed binary;
 
Line 2,959 ⟶ 3,405:
if a < b then
put skip list ('The second number is greater than the first');
</syntaxhighlight>
</lang>
 
=={{header|Plain English}}==
<langsyntaxhighlight lang="plainenglish">To run:
Start up.
Write "Enter the first number: " to the console without advancing.
Line 2,972 ⟶ 3,418:
If the first number is greater than the second number, write "Greater than!" to the console.
Wait for the escape key.
Shut down.</langsyntaxhighlight>
 
=={{header|Pop11}}==
<langsyntaxhighlight lang="pop11">;;; Comparison procedure
define compare_integers(x, y);
if x > y then
Line 2,991 ⟶ 3,437:
 
;;; Read numbers and call comparison procedure
compare_integers(itemrep(), itemrep());</langsyntaxhighlight>
 
=={{header|PowerShell}}==
<langsyntaxhighlight lang="powershell">$a = [int] (Read-Host a)
$b = [int] (Read-Host b)
 
Line 3,003 ⟶ 3,449:
} elseif ($a -gt $b) {
Write-Host $a is greater than $b`.
}</langsyntaxhighlight>
 
=={{header|PureBasic}}==
<lang PureBasic>If OpenConsole()
 
Print("Enter an integer: ")
x.i = Val(Input())
Print("Enter another integer: ")
y.i = Val(Input())
 
If x < y
Print( "The first integer is less than the second integer.")
ElseIf x = y
Print("The first integer is equal to the second integer.")
ElseIf x > y
Print("The first integer is greater than the second integer.")
EndIf
 
Print(#CRLF$ + #CRLF$ + "Press ENTER to exit")
Input()
CloseConsole()
EndIf</lang>
 
=={{header|Python}}==
<langsyntaxhighlight Pythonlang="python">#!/usr/bin/env python
a = input('Enter value of a: ')
b = input('Enter value of b: ')
Line 3,036 ⟶ 3,461:
print 'a is greater than b'
elif a == b:
print 'a is equal to b'</langsyntaxhighlight>
 
(Note: in Python3 ''input()'' will become ''int(input())'')
Line 3,043 ⟶ 3,468:
 
{{works with|Python|2.x only, not 3.x}}
<langsyntaxhighlight Pythonlang="python">#!/usr/bin/env python
import sys
try:
Line 3,057 ⟶ 3,482:
1: 'is greater than'
}
print a, dispatch[cmp(a,b)], b</langsyntaxhighlight>
 
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.
 
=={{header|Quackery}}==
 
<syntaxhighlight lang="quackery">$ "Please enter two numbers separated by a space; "
input quackery cr
say "The first number is "
[ 2dup > iff [ say "larger than" ] done
2dup = iff [ say "equal to" ] done
2dup < if [ say "smaller than" ] ]
2drop
say " the second number." cr</syntaxhighlight>
 
{{out}}
 
Testing in the Quackery shell (REPL).
 
<pre>/O> $ "Please enter two numbers separated by a space; "
... input quackery cr
... say "The first number is "
... [ 2dup > iff [ say "larger than" ] done
... 2dup = iff [ say "equal to" ] done
... 2dup < if [ say "smaller than" ] ]
... 2drop
... say " the second number." cr
...
Please enter two numbers separated by a space; 4 2
 
The first number is larger than the second number.
 
Stack empty.</pre>
 
=={{header|R}}==
<langsyntaxhighlight Rlang="r">print("insert number a")
a <- scan(what=numeric(0), nmax=1)
print("insert number b")
Line 3,072 ⟶ 3,527:
} else if ( a == b ) { # could be simply else of course...
print("a and b are the same")
}</langsyntaxhighlight>
 
=={{header|Racket}}==
<langsyntaxhighlight Racketlang="racket">#lang racket
(define (compare-two-ints a b)
(define compared
Line 3,083 ⟶ 3,538:
(format "~a ~a ~a" a compared b))
(compare-two-ints (read) (read))</langsyntaxhighlight>
 
=={{header|Raku}}==
(formerly Perl 6)
<syntaxhighlight lang="raku" perl6line>my $a = prompt("1st int: ").floor;
my $b = prompt("2nd int: ").floor;
 
Line 3,098 ⟶ 3,553:
elsif $a == $b {
say 'Equal';
}</langsyntaxhighlight>
 
With <code><=></code>:
 
<syntaxhighlight lang="raku" perl6line>say <Less Equal Greater>[($a <=> $b) + 1];</langsyntaxhighlight>
 
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:
 
<syntaxhighlight lang="raku" perl6line>say prompt("1st int: ") <=> prompt("2nd int: ");</langsyntaxhighlight>
 
=={{header|Rapira}}==
<syntaxhighlight lang="rapira">output: "Enter two integers, a and b"
input: a
input: b
 
case
when a > b:
output: "a is greater than b"
when a < b:
output: "a is less than b"
when a = b:
output: "a is equal to b"
esac</syntaxhighlight>
 
=={{header|Raven}}==
<langsyntaxhighlight Ravenlang="raven">"Enter the first number: " print
expect trim 1.1 prefer as $a
"Enter the second number: " print
Line 3,116 ⟶ 3,585:
$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 equal to %g\n" print</langsyntaxhighlight>
 
=={{header|REBOL}}==
<syntaxhighlight lang="rebol">
<lang REBOL>
REBOL [
Title: "Comparing Two Integers"
Line 3,133 ⟶ 3,602:
]
print [a "is" case relation b]
</syntaxhighlight>
</lang>
 
==={{header|Relation}}===
There is no input, so numbers have to be given in code
<syntaxhighlight lang="relation">
<lang Relation>
set a = 15
set b = 21
Line 3,149 ⟶ 3,618:
end if
end if
</syntaxhighlight>
</lang>
 
=={{header|Red}}==
{{trans|REBOL}}
<syntaxhighlight lang="rebol">Red [
Title: "Comparing Two Integers"
URL: http://rosettacode.org/wiki/Comparing_two_integers
Date: 2021-10-25
]
 
a: to-integer ask "First integer? " b: to-integer ask "Second integer? "
 
relation: [
a < b "less than"
a = b "equal to"
a > b "greater than"
]
print [a "is" case relation b]</syntaxhighlight>
 
=={{header|ReScript}}==
 
<syntaxhighlight lang="rescript">let my_compare = (a, b) => {
if a < b { "A is less than B" } else
if a > b { "A is greater than B" } else
if a == b { "A equals B" }
else { "cannot compare NANs" }
}
 
let a = int_of_string(Sys.argv[2])
let b = int_of_string(Sys.argv[3])
 
Js.log(my_compare(a, b))</syntaxhighlight>
{{out}}
<pre>
$ bsc compint.res > compint.bs.js
$ node compint.bs.js 4 2
A is greater than B
$ node compint.bs.js 2 3
A is less than B
$ node compint.bs.js 1 1
A equals B
</pre>
 
=={{header|Retro}}==
Taking the numbers from the stack:
 
<langsyntaxhighlight Retrolang="retro">:example (ab-)
dup-pair gt? [ 'A>B s:put nl ] if
dup-pair lt? [ 'A<B s:put nl ] if
eq? [ 'A=B s:put nl ] if ;</langsyntaxhighlight>
 
=={{header|REXX}}==
<langsyntaxhighlight REXXlang="rexx">/*REXX program prompts for two integers, compares them, and displays the results.*/
numeric digits 2000 /*for the users that really go ka─razy.*/
@=copies('─', 20) /*eyeball catcher for the user's eyen. */
Line 3,183 ⟶ 3,693:
end /*forever*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
serr: say @ '***error*** ' arg(1); say @ "Please try again."; return</langsyntaxhighlight>
{{out|output|text=&nbsp; (shows user input and computer program output together):}}
<pre>
Line 3,211 ⟶ 3,721:
 
=={{header|Ring}}==
<langsyntaxhighlight lang="ring">
Func Compare a,b
if a < b
Line 3,220 ⟶ 3,730:
See "A equals B"
ok
</syntaxhighlight>
</lang>
 
=={{header|Rockstar}}==
Line 3,226 ⟶ 3,736:
Minimized Rockstar:
 
<syntaxhighlight lang="rockstar">
<lang Rockstar>
(Get two numbers from user)
Listen to Number One
Line 3,241 ⟶ 3,751:
If Number One is less than Number Two
Say "The first is less than the second"
</syntaxhighlight>
</lang>
 
Idiomatic version:
<syntaxhighlight lang="rockstar">
<lang Rockstar>
Listen to your soul
Listen to my words
Line 3,256 ⟶ 3,766:
If your soul is smaller than my words,
Say "The second was bigger".
</syntaxhighlight>
</lang>
 
=={{header|RPG}}==
Line 3,263 ⟶ 3,773:
CALL rc_intcmp (x'00000000' x'00000001')
 
<syntaxhighlight lang="rpg">
<lang RPG>
h dftactgrp(*no)
 
Line 3,286 ⟶ 3,796:
dsply message;
*inlr = *on;
</syntaxhighlight>
</lang>
 
=={{header|RPL}}==
≪ '''IF''' DUP2 < '''THEN''' "a < b" ROT ROT '''END'''
'''IF''' DUP2 == '''THEN''' "a = b" ROT ROT '''END'''
'''IF''' > '''THEN''' "a > b" '''END'''
≫ 'COMPR' STO
{{in}}
<pre>
3 5 COMPR
</pre>
{{out}}
<pre>
1: "a < b"
</pre>
 
=={{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".)
 
<langsyntaxhighlight lang="ruby">a = (print "enter a value for a: "; 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 greater than #{b}" if a > b
puts "#{a} is equal to #{b}" if a == b</langsyntaxhighlight>
 
Another way:
 
<langsyntaxhighlight lang="ruby">a = (print "enter a value for a: "; gets).to_i
b = (print "enter a value for b: "; gets).to_i
 
Line 3,307 ⟶ 3,831:
when 0; puts "#{a} is equal to #{b}"
when +1; puts "#{a} is greater than #{b}"
end</langsyntaxhighlight>
 
Example '''input''' and output:
Line 3,325 ⟶ 3,849:
 
An alternative method, which is similar to the python version mentioned above (at the time of writing this) is:
<langsyntaxhighlight lang="ruby"># Function to make prompts nice and simple to abuse
def prompt str
print str, ": "
Line 3,348 ⟶ 3,872:
 
# I hope you can figure this out
puts "#{a} is #{dispatch[a<=>b]} #{b}"</langsyntaxhighlight>
 
=={{header|Run BASIC}}==
<lang runbasic>input "1st number:"; n1
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 greater than 2nd number";n2
if n1 = n2 then print "1st number ";n1;" is equal to 2nd number";n2</lang>
 
=={{header|Rust}}==
Reading from stdin into a string is cumbersome at the moment, but convenience functions will be implemented in the future.
<langsyntaxhighlight lang="rust">use std::io::{self, BufRead};
 
fn main() {
Line 3,378 ⟶ 3,894:
println!("{} is greater than {}" , a , b)
};
}</langsyntaxhighlight>
 
=={{header|SAS}}==
<langsyntaxhighlight lang="sas">/* Showing operators and their fortran-like equivalents. Note that ~= and ^= both mean "different" */
data _null_;
input a b;
Line 3,403 ⟶ 3,919:
1 1
;
run;</langsyntaxhighlight>
 
=={{header|Scala}}==
<langsyntaxhighlight lang="scala">object IntCompare {
def main(args: Array[String]): Unit = {
val a=Console.readInt
Line 3,417 ⟶ 3,933:
printf("%d is greater than %d\n", a, b)
}
}</langsyntaxhighlight>
 
=={{header|Scheme}}==
<langsyntaxhighlight lang="scheme">(define (my-compare a b)
(cond ((< a b) "A is less than B")
((> a b) "A is greater than B")
((= a b) "A equals B")))
 
(my-compare (read) (read))</langsyntaxhighlight>
 
=={{header|Seed7}}==
<langsyntaxhighlight lang="seed7">$ include "seed7_05.s7i";
 
const proc: main is func
Line 3,449 ⟶ 3,965:
writeln(a <& " is greater than " <& b);
end if;
end func;</langsyntaxhighlight>
 
=={{header|SenseTalk}}==
 
<langsyntaxhighlight lang="sensetalk">Ask "Provide Any Number"
 
Put It into A
Line 3,471 ⟶ 3,987:
If A is Equal to B
Put A& " is Equal to " &B
End If</langsyntaxhighlight>
 
=={{header|Sidef}}==
<langsyntaxhighlight lang="ruby">var a = read("a: ", Number);
var b = read("b: ", Number);
 
Line 3,485 ⟶ 4,001:
elsif (a > b) {
say 'Greater';
}</langsyntaxhighlight>
{{out}}
<pre>
Line 3,495 ⟶ 4,011:
=={{header|Slate}}==
<langsyntaxhighlight lang="slate">[ |:a :b |
 
( a > b ) ifTrue: [ inform: 'a greater than b\n' ].
Line 3,501 ⟶ 4,017:
( a = b ) ifTrue: [ inform: 'a is equal to b\n' ].
 
] applyTo: {Integer readFrom: (query: 'Enter a: '). Integer readFrom: (query: 'Enter b: ')}.</langsyntaxhighlight>
 
=={{header|Smalltalk}}==
 
<langsyntaxhighlight lang="smalltalk">| a b |
'a = ' display. a := (stdin nextLine asInteger).
'b = ' display. b := (stdin nextLine asInteger).
( a > b ) ifTrue: [ 'a greater than b' displayNl ].
( a < b ) ifTrue: [ 'a less than b' displayNl ].
( a = b ) ifTrue: [ 'a is equal to b' displayNl ].</langsyntaxhighlight>
 
=={{header|SNOBOL4}}==
Line 3,516 ⟶ 4,032:
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.
 
<langsyntaxhighlight SNOBOL4lang="snobol4">* # Get user input
output = 'Enter X,Y:'
trim(input) break(',') . x ',' rem . y
Line 3,523 ⟶ 4,039:
output = eq(x,y) x ' is equal to ' y :s(end)
output = gt(x,y) x ' is greater than ' y
end</langsyntaxhighlight>
 
=={{header|SNUSP}}==
There are no built-in comparison operators, but you can (destructively) check which of two adjacent cells is most positive.
<langsyntaxhighlight lang="snusp">++++>++++ a b !/?\<?\# a=b
> - \# a>b
- <
a<b #\?/</langsyntaxhighlight>
 
=={{header|Sparkling}}==
<langsyntaxhighlight lang="sparkling">let a = 13, b = 37;
if a < b {
print("a < b");
Line 3,542 ⟶ 4,058:
} else {
print("either a or b or both are NaN");
}</langsyntaxhighlight>
 
=={{header|SQL}}==
{{works with|Oracle}}
<langsyntaxhighlight lang="sql">
drop table test;
 
Line 3,568 ⟶ 4,084:
from test
where a > b;
</syntaxhighlight>
</lang>
 
<pre>
Line 3,590 ⟶ 4,106:
{{works with|Db2 LUW}}
With SQL only:
<langsyntaxhighlight lang="sql pl">
CREATE TABLE TEST (
VAL1 INT,
Line 3,606 ⟶ 4,122:
END COMPARISON
FROM TEST;
</syntaxhighlight>
</lang>
Output:
<pre>
Line 3,638 ⟶ 4,154:
{{works with|Db2 LUW}} version 9.7 or higher.
With SQL PL:
<langsyntaxhighlight lang="sql pl">
--#SET TERMINATOR @
 
Line 3,656 ⟶ 4,172:
CALL COMPARISON(2, 2) @
CALL COMPARISON(2, 1) @
</syntaxhighlight>
</lang>
Output:
<pre>
Line 3,708 ⟶ 4,224:
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.
<langsyntaxhighlight lang="ssem">10101000000000100000000000000000 0. -21 to c
10101000000001100000000000000000 1. c to 21
10101000000000100000000000000000 2. -21 to c
Line 3,728 ⟶ 4,244:
11111111111111111111111111111111 18. -1
11010000000000000000000000000000 19. 11
10110000000000000000000000000000 20. 13</langsyntaxhighlight>
 
=={{header|Standard ML}}==
<langsyntaxhighlight 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 greater than B\n"
Line 3,744 ⟶ 4,260:
compare_integers (a, b)
end
handle Bind => print "Invalid number entered!\n"</langsyntaxhighlight>
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:
<langsyntaxhighlight lang="sml">fun myCompare (a, b) = case Int.compare (a, b) of
LESS => "A is less than B"
| GREATER => "A is greater than B"
| EQUAL => "A equals B"</langsyntaxhighlight>
 
=={{header|Swift}}==
<langsyntaxhighlight Swiftlang="swift">import Cocoa
 
var input = NSFileHandle.fileHandleWithStandardInput()
Line 3,768 ⟶ 4,284:
if (a==b) {println("\(a) equals \(b)")}
if (a < b) {println("\(a) is less than \(b)")}
if (a > b) {println("\(a) is greater than \(b)")}</langsyntaxhighlight>
{{out}}
<pre>
Line 3,779 ⟶ 4,295:
This is not how one would write this in Tcl, but for the sake of clarity:
 
<langsyntaxhighlight lang="tcl">puts "Please enter two numbers:"
 
gets stdin x
Line 3,786 ⟶ 4,302:
if { $x > $y } { puts "$x is greater than $y" }
if { $x < $y } { puts "$x is less than $y" }
if { $x == $y } { puts "$x equals $y" }</langsyntaxhighlight>
 
Other comparison operators are "<=", ">=" and "!=".
Line 3,792 ⟶ 4,308:
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
 
<langsyntaxhighlight lang="tcl">if {int($x) > int($y)} { puts "$x is greater than $y" }</langsyntaxhighlight>
 
or otherwise [[IsNumeric | type can be checked]] with "<tt>if { string is integer $x }...</tt>"
Line 3,799 ⟶ 4,315:
 
A variant that iterates over comparison operators, demonstrated in an interactive [[tclsh]]:
<langsyntaxhighlight Tcllang="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"}}
5 is less than 6
Line 3,807 ⟶ 4,323:
% set j 4
% foreach {o s} {< "less than" > "greater than" == equal} {if [list $i $o $j] {puts "$i is $s $j"}}
5 is greater than 4</langsyntaxhighlight>
 
=={{header|TI-83 BASIC}}==
<lang ti83b>Prompt A,B
If A<B: Disp "A SMALLER B"
If A>B: Disp "A GREATER B"
If A=B: Disp "A EQUAL B"</lang>
 
=={{header|TI-89 BASIC}}==
 
<lang ti89b>Local a, b, result
Prompt a, b
If a < b Then
"<" → result
ElseIf a = b Then
"=" → result
ElseIf a > b Then
">" → result
Else
"???" → result
EndIf
Disp string(a) & " " & result & " " & string(b)</lang>
 
=={{header|Toka}}==
<langsyntaxhighlight lang="toka">[ ( a b -- )
2dup < [ ." a is less than b\n" ] ifTrue
2dup > [ ." a is greater than b\n" ] ifTrue
Line 3,839 ⟶ 4,334:
1 1 compare-integers
2 1 compare-integers
1 2 compare-integers</langsyntaxhighlight>
 
=={{header|TUSCRIPT}}==
<langsyntaxhighlight lang="tuscript">
$$ MODE TUSCRIPT
 
Line 3,853 ⟶ 4,348:
IF (i1<i2) PRINT i1," is less than ",i2
IF (i1>i2) PRINT i1," is greater than ",i2
</syntaxhighlight>
</lang>
 
=={{header|UNIX Shell}}==
Line 3,860 ⟶ 4,355:
{{works with|ksh93}}
 
<langsyntaxhighlight lang="bash">#!/bin/ksh
# tested with ksh93s+
 
Line 3,881 ⟶ 4,376:
fi
 
exit 0</langsyntaxhighlight>
 
One can backport the previous code to pdksh, which has no builtin printf, but can call /usr/bin/printf as an external program.
Line 3,887 ⟶ 4,382:
{{works with|pdksh}}
 
<langsyntaxhighlight lang="bash">#!/bin/ksh
# tested with pdksh
 
Line 3,906 ⟶ 4,401:
fi
 
exit 0</langsyntaxhighlight>
 
----
Line 3,912 ⟶ 4,407:
{{works with|Bash}}
 
<langsyntaxhighlight lang="bash">read -p "Enter two integers: " a b
 
if [ $a -gt $b ]; then comparison="greater than"
Line 3,920 ⟶ 4,415:
fi
 
echo "${a} is ${comparison} ${b}"</langsyntaxhighlight>
 
=={{header|Ursa}}==
<langsyntaxhighlight lang="ursa">decl int first second
out "enter first integer: " console
set first (in int console)
Line 3,937 ⟶ 4,432:
if (> first second)
out first " is greater than " second endl console
end if</langsyntaxhighlight>
 
=={{header|V}}==
<langsyntaxhighlight lang="v">[compare
[ [>] ['less than' puts]
[<] ['greater than' puts]
Line 3,951 ⟶ 4,446:
less than
|2 2 compare
is equal</langsyntaxhighlight>
 
=={{header|Vala}}==
<langsyntaxhighlight lang="vala">
void main(){
int a;
Line 3,972 ⟶ 4,467:
stdout.printf("%d is greater than %d\n", a, b);
}
</syntaxhighlight>
</lang>
 
=={{header|VBA}}==
<lang vb>Public Sub integer_comparison()
first_integer = CInt(InputBox("Give me an integer."))
second_integer = CInt(InputBox("Give me another integer."))
Debug.Print IIf(first_integer < second_integer, "first integer is smaller than second integer", "first integer is not smaller than 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")
End Sub</lang>
 
=={{header|VBScript}}==
Based on the BASIC
=====Implementation=====
<lang vb>
option explicit
 
function eef( b, r1, r2 )
if b then
eef = r1
else
eef = r2
end if
end function
 
dim a, b
wscript.stdout.write "First integer: "
a = cint(wscript.stdin.readline) 'force to integer
 
wscript.stdout.write "Second integer: "
b = cint(wscript.stdin.readline) 'force to integer
 
wscript.stdout.write "First integer is "
if a < b then wscript.stdout.write "less than "
if a = b then wscript.stdout.write "equal to "
if a > b then wscript.stdout.write "greater than "
wscript.echo "Second integer."
 
wscript.stdout.write "First integer is " & _
eef( a < b, "less than ", _
eef( a = b, "equal to ", _
eef( a > b, "greater than ", vbnullstring ) ) ) & "Second integer."
</lang>
 
=={{header|Visual Basic .NET}}==
'''Platform:''' [[.NET]]
 
{{works with|Visual Basic .NET|9.0+}}
<lang vbnet>Sub Main()
 
Dim a = CInt(Console.ReadLine)
Dim b = CInt(Console.ReadLine)
 
'Using if statements
If a < b Then Console.WriteLine("a is less than b")
If a = b Then Console.WriteLine("a equals b")
If a > b Then Console.WriteLine("a is greater than b")
 
'Using Case
Select Case a
Case Is < b
Console.WriteLine("a is less than b")
Case b
Console.WriteLine("a equals b")
Case Is > b
Console.WriteLine("a is greater than b")
End Select
 
End Sub</lang>
 
=={{header|Wart}}==
<langsyntaxhighlight lang="wart">a <- (read)
b <- (read)
prn (if (a < b)
Line 4,050 ⟶ 4,477:
: "a is greater than b"
:else
: "a equals b")</langsyntaxhighlight>
 
=={{header|Wren}}==
<langsyntaxhighlight ecmascriptlang="wren">import "io" for Stdin, Stdout
 
System.print("Enter anything other than a number to quit at any time.\n")
Line 4,074 ⟶ 4,501:
}
System.print()
}</langsyntaxhighlight>
 
{{out}}
Line 4,097 ⟶ 4,524:
 
=={{header|XLISP}}==
<langsyntaxhighlight lang="xlisp">(DEFUN COMPARE-INTEGERS ()
(DISPLAY "Enter two integers separated by a space.")
(NEWLINE)
Line 4,106 ⟶ 4,533:
((> A B) (DISPLAY "The first number is larger."))
((= A B) (DISPLAY "They are equal."))
((< A B) (DISPLAY "The first number is smaller."))))</langsyntaxhighlight>
 
=={{header|XPL0}}==
<langsyntaxhighlight XPL0lang="xpl0">code IntIn=10, Text=12;
int A, B;
[A:= IntIn(0);
Line 4,117 ⟶ 4,544:
if A>B then Text(0, "A>B");
CrLf(0);
]</langsyntaxhighlight>
 
=={{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.
 
<langsyntaxhighlight lang="xml"><xsl:template name="compare">
<xsl:param name="a" select="1"/>
<xsl:param name="b" select="2"/>
Line 4,132 ⟶ 4,559:
</xsl:choose>
</fo:block>
</xsl:template></langsyntaxhighlight>
 
=={{header|zkl}}==
<langsyntaxhighlight 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()</langsyntaxhighlight>
{{out}}
<pre>
Line 4,142 ⟶ 4,569:
greater
</pre>
 
=={{header|ZX Spectrum Basic}}==
<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>
9,476

edits