Integer comparison: Difference between revisions

m
→‎{{header|Wren}}: Changed to Wren S/H
(→‎{{header|Erlang}}: added implementation)
m (→‎{{header|Wren}}: Changed to Wren S/H)
 
(245 intermediate revisions by more than 100 users not shown)
Line 1:
{{task|Basic Data Operations}}
{{task|Basic Data Operations}}[[Category:Arithmetic operations]]{{basic data operation}}Get two integers from the user, and then output if the first one is less, equal or greater than the other. Test the condition ''for each case separately'', so that ''all three comparison operators are used'' in the code.
[[Category:Arithmetic operations]]
{{basic data operation}}
[[Category:Simple]]
 
Get two integers from the user.
 
Then,   display a message if the first integer is:
::::*   less than,
::::*   equal to,   or
::::*   greater than
the second integer.
 
 
Test the condition   ''for each case separately'',   so that   ''all three comparison operators are used''   in the code.
 
 
;Related task:
*   [[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.
<syntaxhighlight lang="360asm">INTCOMP PROLOG
* Reg1=Addr(Addr(argA),Addr(argB))
L 2,0(1) Reg2=Addr(argA)
L 3,4(1) Reg3=Addr(argB)
L 4,0(2) Reg4=argA
L 5,0(3) Reg5=argA
ST 4,A Store R4 in A
ST 5,B Store R5 in B
* if (A < B)
L 0,A load R0
C 0,B compare
BL LOWER branch if lower
* if (A = B)
L 0,A load R0
C 0,B compare
BE EQUAL branch if equal
* if (A < B)
L 0,A load R0
C 0,B compare
BH GREATER branch if higher
* other case ?
B RETURN
LOWER WTO 'A<B'
B RETURN
EQUAL WTO 'A=B'
B RETURN
GREATER WTO 'A>B'
B RETURN
*
RETURN EPILOG
A DS F 31-bit signed integer
B DS F 31-bit signed integer
END</syntaxhighlight>
 
=={{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.
Specific OS/hardware routines for user input and printing are left unimplemented.
<lang 6502asm>Compare PHA ;push Accumulator onto stack
It should be noted that this is strictly an unsigned comparison.
<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 17 ⟶ 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'.
<syntaxhighlight lang="asm">compare:
push psw
cjne a, b, clt
; a == b
; implement code here
jmp compare_
clt:
jc lt
; a > b
; implement code here
jmp compare_
lt:
; a < b
; implement code here
compare_:
pop psw
ret</syntaxhighlight>
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':
<syntaxhighlight 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>
Alternatively one could use the "n:cmp" word
 
=={{header|AArch64 Assembly}}==
{{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>).
<syntaxhighlight lang="arm_assembly">.equ STDOUT, 1
.equ SVC_WRITE, 64
.equ SVC_EXIT, 93
 
.text
.global _start
 
_start:
stp x29, x30, [sp, -16]!
mov x0, #123
mov x1, #456
mov x29, sp
bl integer_compare // integer_compare(123, 456);
mov x0, #-123
mov x1, #-456
bl integer_compare // integer_compare(-123, -456);
mov x0, #123
mov x1, #123
bl integer_compare // integer_compare(123, 123);
ldp x29, x30, [sp], 16
mov x0, #0
b _exit // exit(0);
 
// void integer_compare(long long x, long long y) - compare two signed integers and print a message
integer_compare:
cmp x0, x1
mov x0, #STDOUT
b.eq 1f
b.gt 2f
// x < y
ldr x1, =msg_lt
mov x2, #17
b _write
1: // x == y
ldr x1, =msg_eq
mov x2, #16
b _write
2: // x > y
ldr x1, =msg_gt
mov x2, #20
b _write
 
msg_lt:
.ascii "x is less than y\n"
msg_eq:
.ascii "x is equal to y\n"
msg_gt:
.ascii "x is greater than y\n"
.align 4
 
//////////////// system call wrappers
// ssize_t _write(int fd, void *buf, size_t count)
_write:
stp x29, x30, [sp, -16]!
mov x8, #SVC_WRITE
mov x29, sp
svc #0
ldp x29, x30, [sp], 16
ret
 
// void _exit(int retval)
_exit:
mov x8, #SVC_EXIT
svc #0</syntaxhighlight>
 
=={{header|ABAP}}==
This works in ABAP version 7.40 and above. Note that empty input is evaluated to 0.
 
<syntaxhighlight lang="abap">
report z_integer_comparison.
 
parameters: a type int4, b type int4.
 
data(comparison_result) = cond string(
when a < b " can be replaced by a lt b
then |{ a } is less than { b }|
when a = b " can be replaced by a eq b
then |{ a } is equal to { b }|
when a > b " can be replaced by a gt b
then |{ a } is greater than { b }| ).
 
write comparison_result.
</syntaxhighlight>
 
=={{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 42 ⟶ 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 70 ⟶ 345:
 
return 0;
}</langsyntaxhighlight>
Run as:
<pre>aime FILE integer a 33 integer b 133</pre>
 
=={{header|ALGOL 68}}==
{{works with|ALGOL 68|Revision 1 - no extensions to language used}}
Line 80 ⟶ 356:
{{works with|ELLA ALGOL 68|Any (with appropriate job cards) - tested with release [http://sourceforge.net/projects/algol68/files/algol68toc/algol68toc-1.8.8d/algol68toc-1.8-8d.fc9.i386.rpm/download 1.8-8d]}}
 
Note: the standard includes the characters "&le;", "&ge;" and "&ne;". These appear
These appear in the character sets [[wp:GOST 10859|GOST 10859]], [http://www.w3.org/TR/REC-MathML/chap6/ISOTECH1.html ISOtech] and
IBM's [[:wp:EBCDIC|EBCDIC]] e.g. code page [http://www.tachyonsoft.com/cp00293.htm 293],
and in extended ASCII code pages [http://www.tachyonsoft.com/cp00907.htm 910] & [http://www.tachyonsoft.com/cp00907.htm 910]
Line 87 ⟶ 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 107 ⟶ 383:
print((a," is greater or equal to ", b, new line))
FI
)</langsyntaxhighlight>
{{out}}
Example output:
<pre>
+3 is less or equal to +4
Line 114 ⟶ 390:
+3 is not equal to +4
</pre>
 
=={{header|ALGOL W}}==
<syntaxhighlight lang="algolw">begin
 
integer a, b;
 
write( "first number: " );
read( a );
write( "second number: " );
read( b );
 
if a < b then write( a, " is less than ", b );
if a = b then write( a, " is equal to ", b );
if a > b then write( a, " is greater than ", b );
 
end.</syntaxhighlight>
 
=={{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 127 ⟶ 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">
 
/* ARM assembly Raspberry PI */
/* program comparNumber.s */
 
/* Constantes */
.equ BUFFERSIZE, 100
.equ STDIN, 0 @ Linux input console
.equ STDOUT, 1 @ Linux output console
.equ EXIT, 1 @ Linux syscall
.equ READ, 3 @ Linux syscall
.equ WRITE, 4 @ Linux syscall
/* Initialized data */
.data
szMessNum1: .asciz "Enter number 1 : \n"
szMessNum2: .asciz "Enter number 2: \n"
szMessEqual: .asciz "Number 1 and number 2 are equals.\n"
szMessSmall: .asciz "Number 1 smaller than number 2.\n"
szMessLarge: .asciz "Number 1 larger than number 2.\n"
szCarriageReturn: .asciz "\n"
 
/* UnInitialized data */
.bss
sBuffer: .skip BUFFERSIZE
 
/* code section */
.text
.global main
main: /* entry of program */
push {fp,lr} /* saves 2 registers */
ldr r0,iAdrszMessNum1 @ message address
ldr r1,iAdrsBuffer @ buffer address
mov r2,#BUFFERSIZE
bl numberEntry
mov r5,r0 @ save number 1 -> r5
ldr r0,iAdrszMessNum2 @ message address
ldr r1,iAdrsBuffer @ buffer address
mov r2,#BUFFERSIZE
bl numberEntry
cmp r5,r0 @ compar number 1 and number 2
beq equal
blt small
bgt large
@ never !!
b 100f
equal:
ldr r0,iAdrszMessEqual @ message address
b aff
small:
ldr r0,iAdrszMessSmall @ message address
b aff
large:
ldr r0,iAdrszMessLarge @ message address
b aff
aff:
bl affichageMess @ display message
100: /* standard end of the program */
mov r0, #0 @ return code
pop {fp,lr} @restaur 2 registers
mov r7, #EXIT @ request to exit program
swi 0 @ perform the system call
 
iAdrszMessNum1: .int szMessNum1
iAdrszMessNum2: .int szMessNum2
iAdrszMessEqual: .int szMessEqual
iAdrszMessSmall: .int szMessSmall
iAdrszMessLarge: .int szMessLarge
iAdrsBuffer: .int sBuffer
iAdrszCarriageReturn: .int szCarriageReturn
/******************************************************************/
/* Number entry with display message and conversion number */
/******************************************************************/
/* r0 contains message address */
/* r1 contains buffer address
/* r2 contains buffersize */
/* r0 return a number */
numberEntry:
push {fp,lr} @ save registres */
push {r4,r6,r7} @ save others registers
mov r4,r1 @ save buffer address -> r4
bl affichageMess
mov r0,#STDIN @ Linux input console
//ldr r1,iAdrsBuffer @ buffer address
//mov r2,#BUFFERSIZE @ buffer size
mov r7, #READ @ request to read datas
swi 0 @ call system
mov r1,r4 @ buffer address
mov r2,#0 @ end of string
strb r2,[r1,r0] @ store byte at the end of input string (r0
@
mov r0,r4 @ buffer address
bl conversionAtoD @ conversion string in number in r0
100:
pop {r4,r6,r7} /* restaur others registers */
pop {fp,lr} /* restaur des 2 registres */
bx lr /* return */
/******************************************************************/
/* display text with size calculation */
/******************************************************************/
/* r0 contains the address of the message */
affichageMess:
push {fp,lr} /* save registres */
push {r0,r1,r2,r7} /* save others registers */
mov r2,#0 /* counter length */
1: /* loop length calculation */
ldrb r1,[r0,r2] /* read octet start position + index */
cmp r1,#0 /* if 0 its over */
addne r2,r2,#1 /* else add 1 in the length */
bne 1b /* and loop */
/* so here r2 contains the length of the message */
mov r1,r0 /* address message in r1 */
mov r0,#STDOUT /* code to write to the standard output Linux */
mov r7, #WRITE /* code call system "write" */
swi #0 /* call systeme */
pop {r0,r1,r2,r7} /* restaur others registers */
pop {fp,lr} /* restaur des 2 registres */
bx lr /* return */
 
/******************************************************************/
/* Convert a string to a number stored in a registry */
/******************************************************************/
/* r0 contains the address of the area terminated by 0 or 0A */
/* r0 returns a number */
conversionAtoD:
push {fp,lr} @ save 2 registers
push {r1-r7} @ save others registers
mov r1,#0
mov r2,#10 @ factor
mov r3,#0 @ counter
mov r4,r0 @ save address string -> r4
mov r6,#0 @ positive sign by default
mov r0,#0 @ initialization to 0
1: /* early space elimination loop */
ldrb r5,[r4,r3] @ loading in r5 of the byte located at the beginning + the position
cmp r5,#0 @ end of string -> end routine
beq 100f
cmp r5,#0x0A @ end of string -> end routine
beq 100f
cmp r5,#' ' @ space ?
addeq r3,r3,#1 @ yes we loop by moving one byte
beq 1b
cmp r5,#'-' @ first character is -
moveq r6,#1 @ 1 -> r6
beq 3f @ then move on to the next position
2: /* beginning of digit processing loop */
cmp r5,#'0' @ character is not a number
blt 3f
cmp r5,#'9' @ character is not a number
bgt 3f
/* character is a number */
sub r5,#48
ldr r1,iMaxi @ check the overflow of the register
cmp r0,r1
bgt 99f @ overflow error
mul r0,r2,r0 @ multiply par factor 10
add r0,r5 @ add to r0
3:
add r3,r3,#1 @ advance to the next position
ldrb r5,[r4,r3] @ load byte
cmp r5,#0 @ end of string -> end routine
beq 4f
cmp r5,#0x0A @ end of string -> end routine
beq 4f
b 2b @ loop
4:
cmp r6,#1 @ test r6 for sign
moveq r1,#-1
muleq r0,r1,r0 @ if negatif, multiply par -1
b 100f
99: /* overflow error */
ldr r0,=szMessErrDep
bl affichageMess
mov r0,#0 @ return zero if error
100:
pop {r1-r7} @ restaur other registers
pop {fp,lr} @ restaur 2 registers
bx lr @return procedure
/* constante program */
iMaxi: .int 1073741824
szMessErrDep: .asciz "Too large: overflow 32 bits.\n"
 
</syntaxhighlight>
 
=={{header|Arturo}}==
<syntaxhighlight lang="rebol">a: to :integer input "enter a value for a: "
b: to :integer input "enter a value for 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 equal to" b ] ]</syntaxhighlight>
 
=={{header|Astro}}==
<syntaxhighlight lang="python">let a = input('Enter value of a: ')
let b = input('Enter value of b: ')
 
if a < b:
print 'a is less than b'
elif a > b:
print 'a is greater than b'
elif a == b:
print 'a is equal to b'</syntaxhighlight>
 
=={{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.
The default range is 0 to 100.
<lang autohotkey>Gui, Add, Edit
<syntaxhighlight lang="autohotkey">Gui, Add, Edit
Gui, Add, UpDown, vVar1
Gui, Add, Edit
Line 157 ⟶ 657:
 
GuiClose:
ExitApp</langsyntaxhighlight>
 
=={{header|Avail}}==
<syntaxhighlight lang="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";];</syntaxhighlight>
 
=={{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:
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}}==
<syntaxhighlight lang="axe">Lbl FUNC
If r₁<r₂
Disp "LESS THAN",i
End
If r₁=r₂
Disp "EQUAL TO",i
End
If r₁>r₂
Disp "GREATER THAN",i
End
Return</syntaxhighlight>
 
=={{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}}===
<syntaxhighlight 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</syntaxhighlight>
 
{{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 179 ⟶ 716:
IF a = b THEN PRINT "equal to ";
IF a > b THEN PRINT "greater than ";
PRINT "b"</langsyntaxhighlight>
 
==={{header|BBC BASICBASIC256}}===
<syntaxhighlight lang="freebasic">input "Please enter one integer: ", x
<lang bbcbasic> INPUT "Enter two numbers separated by a comma: " a, b
input "and a second integer: ", 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|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</langsyntaxhighlight>
 
==={{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}}===
<syntaxhighlight lang="is-basic">100 INPUT PROMPT "Enter A: ":A
110 INPUT PROMPT "Enter B: ":B
120 IF A<B THEN
130 PRINT A;"is lesss than ";B
140 ELSE IF A=B THEN
150 PRINT A;"is equal to ";B
160 ELSE
170 PRINT A;"is greater than ";B
180 END IF</syntaxhighlight>
 
or
 
<syntaxhighlight lang="is-basic">100 INPUT PROMPT "Enter A: ":A
110 INPUT PROMPT "Enter B: ":B
120 SELECT CASE A
130 CASE IS<B
140 PRINT A;"is lesss than ";B
150 CASE IS=B
160 PRINT A;"is equal to ";B
170 CASE ELSE
180 PRINT A;"is greater than ";B
190 END SELECT</syntaxhighlight>
 
==={{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}}==
<syntaxhighlight lang="dos">@echo off
setlocal EnableDelayedExpansion
set /p a="A: "
set /p b="B: "
if %a% LSS %b% (
echo %a% is less than %b%
) else ( if %a% GTR %b% (
echo %a% is greater than %b%
) else ( if %a% EQU %b% (
echo %a% is equal to %b%
)))</syntaxhighlight>
{{Out}}
<pre>C:\Test>IntegerComparison.bat
A: 5
B: 3
5 is greater than 3</pre>
 
=={{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.)
<syntaxhighlight 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</syntaxhighlight>
 
=={{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}}==
Befunge only has the greater-than operator (backtick `). The branch commands (underline _ and pipe |) test for zero.
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}}==
<syntaxhighlight 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}" }</syntaxhighlight>
 
=={{header|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
The first one is less than the second one
blsq ) "6 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
They are both equal
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>
 
=={{header|C}}==
<langsyntaxhighlight lang="c">#include <stdio.h>
 
int main()
Line 222 ⟶ 1,166:
 
return 0;
}</langsyntaxhighlight>
 
=={{header|C sharp|C#}}==
<syntaxhighlight lang="csharp">using System;
 
class Program
{
static void Main()
{
int a = int.Parse(Console.ReadLine());
int b = int.Parse(Console.ReadLine());
if (a < b)
Console.WriteLine("{0} is less than {1}", a, b);
if (a == b)
Console.WriteLine("{0} equals {1}", a, b);
if (a > b)
Console.WriteLine("{0} is greater than {1}", a, b);
}
}</syntaxhighlight>
 
=={{header|C++}}==
<langsyntaxhighlight lang="cpp">#include <iostream>
using namespace std;
 
int main()
{
int a, b;
 
cin >> a >> b;
if (!(std::cin >> a >> b)) {
std::cerr << "could not read the numbers\n";
return 1;
}
 
// test for less-than
if (a < b)
std::cout << a << " is less than " << b << endl"\n";
 
// test for equality
if (a == b)
std::cout << a << " is equal to " << b << endl"\n";
 
// test for greater-than
if (a > b)
std::cout << a << " is greater than " << b << endl"\n";
}</langsyntaxhighlight>
 
=={{header|C sharp|C#CFEngine}}==
<syntaxhighlight lang="cfengine3">
<lang csharp>using System;
bundle agent __main__
{
vars:
# Change the values to test:
"first_integer" int => "10";
"second_integer" int => "9";
 
reports:
class Program
"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)
{
if(one < two) <<< one, " is less than ", two >>>;
static void Main()
if(one == two) <<< one, " is equal than ", two >>>;
{
if(one > two) <<< one, " is greater than ", two >>>;
int a = int.Parse(Console.ReadLine());
}
int b = int.Parse(Console.ReadLine());
// uncomment next line and change values to test
if (a < b)
// intComparison (2,4);
Console.WriteLine("{0} is less than {1}", a, b);
</syntaxhighlight>
if (a == b)
Console.WriteLine("{0} equals {1}", a, b);
if (a > b)
Console.WriteLine("{0} is greater than {1}", a, b);
}
}</lang>
 
=={{header|Clean}}==
<langsyntaxhighlight lang="clean">import StdEnv
 
compare a b
Line 276 ⟶ 1,254:
(_, a, console) = freadi console
(_, b, console) = freadi console
= compare a b</langsyntaxhighlight>
 
=={{header|Clipper}}==
<syntaxhighlight lang="clipper"> Function Compare(a, b)
IF a < b
? "A is less than B"
ELSEIF a > b
? "A is more than B"
ELSE
? "A equals B"
ENDIF
Return Nil
</syntaxhighlight>
 
=={{header|Clojure}}==
Creates an infinite sequence of calls to "read an object from the user", and assigns the first two elements to a and b, without evaluating the rest. 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.
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.
<lang Clojure>(let [[a b] (repeatedly read)]
Note that this does no validation on input: if the user inputs a string then an exception will be thrown.
<syntaxhighlight lang="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 306 ⟶ 1,298:
if(A GREATER B)
message(STATUS "${A} is greater than ${B}")
endif()</langsyntaxhighlight>
 
=={{header|COBOL}}==
{{works with|OpenCOBOL}}
<syntaxhighlight lang="cobol"> IDENTIFICATION DIVISION.
PROGRAM-ID. Int-Compare.
 
DATA DIVISION.
WORKING-STORAGE SECTION.
01 A PIC 9(10).
01 B PIC 9(10).
 
PROCEDURE DIVISION.
DISPLAY "First number: " WITH NO ADVANCING
ACCEPT A
DISPLAY "Second number: " WITH NO ADVANCING
ACCEPT B
 
* *> Note: Longer verbal forms may be used instead of symbols
* *> e.g. 'IS GREATER THAN' instead '<'
IF A < B
DISPLAY A " is less than " B
ELSE IF A = B
DISPLAY A " is equal to " B
ELSE IF A > B
DISPLAY A " is larger than " B
END-IF.
 
GOBACK
.</syntaxhighlight>
 
=={{header|ColdFusion}}==
 
* '''Less than:''' LT
* '''Less than or equal to:''' LTE
* '''Greater than:''' GT
* '''Greater than or equal to:''' GTE
* '''Equal to:''' EQ
* '''Not equal to:''' NEQ
 
===In CFML===
 
<syntaxhighlight lang="cfm"><cffunction name="CompareInteger">
<cfargument name="Integer1" type="numeric">
<cfargument name="Integer2" type="numeric">
<cfset VARIABLES.Result = "" >
<cfif ARGUMENTS.Integer1 LT ARGUMENTS.Integer2 >
<cfset VARIABLES.Result = VARIABLES.Result & "(" & ARGUMENTS.Integer1 & " is less than " & ARGUMENTS.Integer2 & ")" >
</cfif>
<cfif ARGUMENTS.Integer1 LTE ARGUMENTS.Integer2 >
<cfset VARIABLES.Result = VARIABLES.Result & "(" & ARGUMENTS.Integer1 & " is less than or equal to " & ARGUMENTS.Integer2 & ")" >
</cfif>
<cfif ARGUMENTS.Integer1 GT ARGUMENTS.Integer2 >
<cfset VARIABLES.Result = VARIABLES.Result & "(" & ARGUMENTS.Integer1 & " is greater than " & ARGUMENTS.Integer2 & ")" >
</cfif>
<cfif ARGUMENTS.Integer1 GTE ARGUMENTS.Integer2 >
<cfset VARIABLES.Result = VARIABLES.Result & "(" & ARGUMENTS.Integer1 & " is greater than or equal to " & ARGUMENTS.Integer2 & ")" >
</cfif>
<cfif ARGUMENTS.Integer1 EQ ARGUMENTS.Integer2 >
<cfset VARIABLES.Result = VARIABLES.Result & "(" & ARGUMENTS.Integer1 & " is equal to " & ARGUMENTS.Integer2 & ")" >
</cfif>
<cfif ARGUMENTS.Integer1 NEQ ARGUMENTS.Integer2 >
<cfset VARIABLES.Result = VARIABLES.Result & "(" & ARGUMENTS.Integer1 & " is not equal to " & ARGUMENTS.Integer2 & ")" >
</cfif>
<cfreturn VARIABLES.Result >
</cffunction></syntaxhighlight>
 
===In CFScript===
 
<syntaxhighlight lang="cfm"><cfscript>
function CompareInteger( Integer1, Integer2 ) {
VARIABLES.Result = "";
if ( ARGUMENTS.Integer1 LT ARGUMENTS.Integer2 ) {
VARIABLES.Result = VARIABLES.Result & "(" & ARGUMENTS.Integer1 & " is less than " & ARGUMENTS.Integer2 & ")";
}
if ( ARGUMENTS.Integer1 LTE ARGUMENTS.Integer2 ) {
VARIABLES.Result = VARIABLES.Result & "(" & ARGUMENTS.Integer1 & " is less than or equal to " & ARGUMENTS.Integer2 & ")";
}
if ( ARGUMENTS.Integer1 GT ARGUMENTS.Integer2 ) {
VARIABLES.Result = VARIABLES.Result & "(" & ARGUMENTS.Integer1 & " is greater than " & ARGUMENTS.Integer2 & ")";
}
if ( ARGUMENTS.Integer1 GTE ARGUMENTS.Integer2 ) {
VARIABLES.Result = VARIABLES.Result & "(" & ARGUMENTS.Integer1 & " is greater than or equal to " & ARGUMENTS.Integer2 & ")";
}
if ( ARGUMENTS.Integer1 EQ ARGUMENTS.Integer2 ) {
VARIABLES.Result = VARIABLES.Result & "(" & ARGUMENTS.Integer1 & " is equal to " & ARGUMENTS.Integer2 & ")";
}
if ( ARGUMENTS.Integer1 NEQ ARGUMENTS.Integer2 ) {
VARIABLES.Result = VARIABLES.Result & "(" & ARGUMENTS.Integer1 & " is not equal to " & ARGUMENTS.Integer2 & ")";
}
return VARIABLES.Result;
}
</cfscript></syntaxhighlight>
 
=={{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 319 ⟶ 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. You can enter the two numbers, and the result will print immediately. Alternatively, you can wrap this code in a function definition:
You can enter the two numbers, and the result will print immediately.
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 332 ⟶ 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:
(compare-integers)
 
=={{header|Computer/zero Assembly}}==
The only conditional instruction we have is <tt>BRZ</tt> (branch on accumulator zero). We can therefore test for equality very quickly. To test for "greater than" or "less than", however, requires a loop.
 
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.
<syntaxhighlight lang="czasm">start: STP ; get input
 
x: NOP
y: NOP
 
LDA x
SUB y
BRZ start ; x=y, A=0
 
loop: LDA x
SUB one
BRZ x<y
STA x
 
LDA y
SUB one
BRZ x>y
STA y
 
JMP loop
 
x>y: LDA one ; A := 1
JMP start
 
x<y: SUB one ; A := 0-1
JMP start
 
one: 1</syntaxhighlight>
 
=={{header|D}}==
<syntaxhighlight lang="d">void main() {
<lang d>import std.stdio, std.conv, std.string;
import std.stdio, std.conv, std.string;
 
void main() {
int a = 10, b = 20;
try {
a = to!int(readln().strip()).to!int;
b = to!int(readln().strip()).to!int;
} catch (StdioException) {}
 
Line 355 ⟶ 1,474:
if (a > b)
writeln(a, " is greater than ", b);
}</langsyntaxhighlight>
{{out}}
<pre>10 is less than 20</pre>
 
=={{header|Dc}}==
<syntaxhighlight lang="dc">[Use _ (underscore) as negative sign for numbers.]P []pP
[Enter two numbers to compare: ]P
? sbsa
[[greater than]]sp lb la >p
[ [less than]]sp lb la <p
[ [equal to]]sp lb la =p
la n [ is ]P P [ ]P lbn []pP
</syntaxhighlight>
{{out}}
44 is greater than 3
 
=={{header|DCL}}==
<syntaxhighlight lang="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"</syntaxhighlight>
{{out}}
<pre>$ @integer_comparison
Please provide an integer: 0
Please provide another: -3
the first integer is greater
$ @integer_comparison
Please provide an integer: -2000
Please provide another: 12355
the first integer is less
$ @integer_comparison
Please provide an integer: 314
Please provide another: 314
the integers have the same value</pre>
 
=={{header|Delphi}}==
:''Slightly different than the [[#Pascal|Pascal]] example''
 
<langsyntaxhighlight Delphilang="delphi">program IntegerCompare;
 
{$APPTYPE CONSOLE}
Line 369 ⟶ 1,520:
a, b: Integer;
begin
Readln(a, b);
if (a < b) then Writeln(a, ' is less than ', b);
if (a =< b) then Writeln(a, ' is equalless tothan ', b);
if (a >= b) then Writeln(a, ' is greaterequal thanto ', b);
if a > b then Writeln(a, ' is greater than ', b);
end.</lang>
end.</syntaxhighlight>
 
=={{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}}==
 
{{trans|Clipper}}
 
<syntaxhighlight lang="dyalect">func compare(a, b) {
if a < b {
"A is less than B"
} else if a > b {
"A is more than B"
} else {
"A equals B"
}
}</syntaxhighlight>
 
=={{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
print "less"
.
if a = b
print "equal"
.
if a > b
print "greater"
.</syntaxhighlight>
 
=={{header|ECL}}==
<syntaxhighlight lang="ecl">
CompareThem(INTEGER A,INTEGER B) := FUNCTION
Result := A <=> B;
STRING ResultText := CASE (Result,1 => 'is greater than', 0 => 'is equal to','is less than');
RETURN A + ' ' + TRIM(ResultText) + ' ' + B;
END;
 
CompareThem(1,2); //Shows "1 is less than 2"
CompareThem(2,2); //Shows "2 is equal to 2"
CompareThem(2,1); //Shows "2 is greater than 1"
</syntaxhighlight>
 
=={{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.
<syntaxhighlight lang="edsac">[ Integer comparison
==================
A program for the EDSAC
Illustrates the use of the E
(branch on accumulator sign
bit clear) and G (branch on
accumulator sign bit set)
orders
The integers to be tested, x
and y, should be stored in
addresses 13@ and 14@
Output: the program causes the
machine to print
'+' if x > y,
'=' if x = y,
'-' if x < y.
Works with Initial Orders 2 ]
 
T56K [ load point ]
GK [ base address ]
O15@ [ figure shift ]
A13@ [ a = x ]
S14@ [ a -= y ]
G10@ [ if a<0 go to 10 ]
S12@ [ a -= 1 ]
E8@ [ if a>=0 go to 8 ]
O17@ [ write '=' ]
ZF [ halt ]
[ 8 ] O16@ [ write '+' ]
ZF [ halt ]
[ 10 ] O18@ [ write '-' ]
ZF [ halt ]
[ 12 ] P0D [ const: 1 ]
[ 13 ] P16D [ x = 37 ]
[ 14 ] P14F [ y = 28 ]
[ 15 ] #F [ figure shift ]
[ 16 ] ZF [ + character ]
[ 17 ] VF [ = character ]
[ 18 ] AF [ - character ]
EZPF [ begin execution ]</syntaxhighlight>
 
=={{header|Efene}}==
Line 386 ⟶ 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 415 ⟶ 1,676:
compare(4, 5)
}
</syntaxhighlight>
</lang>
 
=={{header|Eiffel}}==
<syntaxhighlight lang="eiffel">class
APPLICATION
inherit
ARGUMENTS
create
make
 
feature {NONE} -- Initialization
 
make
local
i, j: INTEGER_32
do
io.read_integer_32
i := io.last_integer_32
 
io.read_integer_32
j := io.last_integer_32
 
if i < j then
print("first is less than second%N")
end
if i = j then
print("first is equal to the second%N")
end
if i > j then
print("first is greater than second%N")
end
end
end</syntaxhighlight>
 
=={{header|Elena}}==
ELENA 4.x:
<syntaxhighlight lang="elena">import extensions;
public program()
{
var a := console.readLine().toInt();
var b := console.readLine().toInt();
if (a < b)
{ console.printLine(a," is less than ",b) };
if (a == b)
{ console.printLine(a," equals ",b) };
if (a > b)
{ console.printLine(a," is greater than ",b) }
}</syntaxhighlight>
 
=={{header|Elixir}}==
<syntaxhighlight lang="elixir">{a,_} = IO.gets("Enter your first integer: ") |> Integer.parse
{b,_} = IO.gets("Enter your second integer: ") |> Integer.parse
 
cond do
a < b ->
IO.puts "#{a} is less than #{b}"
a > b ->
IO.puts "#{a} is greater than #{b}"
a == b ->
IO.puts "#{a} is equal to #{b}"
end</syntaxhighlight>
 
=={{header|Emacs Lisp}}==
 
<syntaxhighlight lang="lisp">(defun integer-comparison (a b)
"Compare A to B and print the outcome in the message buffer."
(interactive "nFirst integer ⇒\nnSecond integer ⇒")
(cond
((< 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>
 
Invoke from within Emacs Lisp (or e.g., with <code>M-:</code>) as <code>(integer-comparison 12 42)</code>
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 430 ⟶ 1,796:
io:format("~b is equal to ~b~n",[N,M])
end.
if
</lang>
N =< M ->
io:format("~b is less than or equal to ~b~n",[N,M]);
N >= M ->
io:format("~b is greater than or equal to ~b~n",[N,M])
end.
 
</syntaxhighlight>
 
=={{header|Euphoria}}==
<langsyntaxhighlight Euphorialang="euphoria">include get.e
 
integer a,b
Line 447 ⟶ 1,820:
puts(1,"grater then")
end if
puts(1," b")</langsyntaxhighlight>
 
=={{header|Excel}}==
 
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:
 
<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)))
</syntaxhighlight>
 
In a Google Docs spreadsheet, that becomes :
 
<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)))
</syntaxhighlight>
 
=={{header|F_Sharp|F#}}==
<syntaxhighlight lang="fsharp">let compare_ints a b =
let r =
match a with
| x when x < b -> -1, printfn "%d is less than %d" x b
| x when x = b -> 0, printfn "%d is equal to %d" x b
| x when x > b -> 1, printfn "%d is greater than %d" x b
| x -> 0, printf "default condition (not reached)"
fst r</syntaxhighlight>
 
=={{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 467 ⟶ 1,865:
Uses Env.cur to access stdin and stdout.
 
<langsyntaxhighlight lang="fantom">class Main
{
public static Void main ()
Line 489 ⟶ 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 505 ⟶ 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 512 ⟶ 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 535 ⟶ 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 546 ⟶ 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 561 ⟶ 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 576 ⟶ 1,983:
end if
 
end program compare</langsyntaxhighlight>
 
=={{header|friendly interactive shell}}==
<syntaxhighlight lang="fishshell">read a
read b
 
if test $a -gt $b
echo Greater
else if test $a -lt $b
echo Less
else if test $a -eq $b
echo Equal
end</syntaxhighlight>
 
=={{header|Frink}}==
All integers in Frink can be arbitrarily large.
<lang frink>
 
[a,b] = input["Enter numbers",["a","b"]]
<syntaxhighlight lang="frink">[a,b] = eval[input["Enter numbers",["a","b"]]]
if a<b
println["$a < $b"]
Line 586 ⟶ 2,006:
println["$a == $b"]
if a>b
println["$a > $b"]</syntaxhighlight>
</lang>
 
=={{header|F_Sharp|F#FunL}}==
<syntaxhighlight lang="funl">import console.readInt
<lang fsharp>let compare_ints a b =
 
let r =
a = readInt()
match a with
b = readInt()
| x when x < b -> -1, printfn "%d is less than %d" x b
 
| x when x = b -> 0, printfn "%d is equal to %d" x b
val (_, c) = [((<), 'less than'), ((==), |'equal x when xto'), ((> b -> 1), printfn "%d is 'greater than')].find( %d"(compare, x_) -> compare(a, b) ).get()
 
| x -> 0, printf "default condition (not reached)"
println( "$a is $c $b." )</syntaxhighlight>
fst r</lang>
 
=={{header|Fōrmulæ}}==
 
{{FormulaeEntry|page=https://formulae.org/?script=examples/Integer_comparison}}
 
'''Solution'''
 
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.
 
[[File:Fōrmulæ - Integer comparison 01.png]]
 
[[File:Fōrmulæ - Integer comparison 02.png]]
 
However, a simple function can be written for the requirement:
 
[[File:Fōrmulæ - Integer comparison 03.png]]
 
[[File:Fōrmulæ - Integer comparison 04.png]]
 
[[File:Fōrmulæ - Integer comparison 05.png]]
 
=={{header|Go}}==
<langsyntaxhighlight lang="go">package main
 
import (
"fmt"
"log"
"bufio"
"os"
"strconv"
"strings"
)
 
func main() {
var n1, n2 int
in := bufio.NewReader(os.Stdin)
fmt.Print("enter number: ")
getInt := func() int {
if _, err := fmt.Scan(&n1); err != nil {
fmt.Print("Integer: ")
log.Fatal(err)
s, err := in.ReadString('\n')
}
if err != nil {
fmt.Print("enter number: ")
fmt.Println("\nComputer says input error")
if _, err := fmt.Scan(&n2); err != nil {
os.Exit(0)
log.Fatal(err)
}
}
i, err := strconv.Atoi(strings.TrimSpace(s))
switch {
if err != nil {
case n1 < n2:
fmt.Println("Not an integer")
fmt.Println(n1, "less than", n2)
os.Exit(0)
case n1 == n2:
}
fmt.Println(n1, "equal to", n2)
return i
case n1 > }n2:
fmt.Println(n1, "greater than", n2)
 
}
n1 := getInt()
}</syntaxhighlight>
n2 := getInt()
 
switch {
case n1 < n2: fmt.Println(n1, "less than", n2)
case n1 == n2: fmt.Println(n1, "equal to", n2)
case n1 > n2: fmt.Println(n1, "greater than", n2)
}
}</lang>
 
=={{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}}
Output:
<pre>a ? b = 2000 ? 3 = a > b
a ? b = 2000 ? 300000 = a < b
Line 656 ⟶ 2,085:
==="Spaceship" (compareTo) Operator===
Using spaceship operator and a lookup table:
<syntaxhighlight lang="groovy">final rels = [ (-1) : '<', 0 : '==', 1 : '>' ].asImmutable()
<lang groovy>def comparison = { a, b ->
def comparisonSpaceship = { a, b ->
def rels = [ (-1) : '<', 0 : '==', 1 : '>' ]
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}}
Output:
<pre>a ? b = 2000 ? 3 = a > b
a ? b = 2000 ? 300000 = a < b
a ? b = 2000 ? 2000 = a == b</pre>
 
=={{header|Harbour}}==
<syntaxhighlight lang="visualfoxpro">PROCEDURE Compare( a, b )
 
IF a < b
? "A is less than B"
ELSEIF a > b
? "A is more than B"
ELSE
? "A equals B"
ENDIF
 
RETURN</syntaxhighlight>
 
=={{header|Haskell}}==
<langsyntaxhighlight lang="haskell">myCompare a:: Integer -> Integer -> bString
myCompare a b
| a < b = "A is less than B"
| a > b = "A is greater than B"
| a == b = "A equals B"
 
main = do
a' <- getLinereadLn
b' <- getLinereadLn
putStrLn $ myCompare a b</syntaxhighlight>
let { a :: Integer; a = read a' }
let { b :: Integer; b = read b' }
putStrLn $ myCompare a b</lang>
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}}==
<syntaxhighlight lang="hexiscript">let a scan int
let b scan int
 
if a < b
println a + " is less than " + b
endif
 
if a > b
println a + " is greater than " + b
endif
 
if a = b
println a + " is equal to " + b
endif</syntaxhighlight>
 
=={{header|HicEst}}==
<langsyntaxhighlight lang="hicest">DLG(NameEdit=a, NameEdit=b, Button='OK')
IF (a < b) THEN
Line 697 ⟶ 2,155:
ELSEIF(a > b) THEN
WRITE(Messagebox) a, ' is greater than ', b
ENDIF</langsyntaxhighlight>
 
=={{header|HolyC}}==
<syntaxhighlight lang="holyc">I64 *a, *b;
a = Str2I64(GetStr("Enter your first number: "));
b = Str2I64(GetStr("Enter your second number: "));
 
if (a < b)
Print("%d is less than %d\n", a, b);
 
if (a == b)
Print("%d is equal to %d\n", a, b);
 
if (a > b)
Print("%d is greater than %d\n", a, b);</syntaxhighlight>
 
=={{header|Hy}}==
<syntaxhighlight 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"]))</syntaxhighlight>
 
=={{header|i}}==
<syntaxhighlight lang="i">software {
a = number(read(' '))
b = number(read())
if a < b
print(a, " is less than ", b)
end
if a = b
print(a, " is equal to ", b)
end
if a > b
print(a, " is greater than ", b)
end
}</syntaxhighlight>
 
=={{header|Icon}} and {{header|Unicon}}==
<langsyntaxhighlight Iconlang="icon">procedure main()
 
until integer(a) do {
Line 715 ⟶ 2,213:
write(a," = ", a = b)
write(a," > ", a > b)
end</langsyntaxhighlight>
 
{{out}}
Sample Output:
<pre>#int_compare.exe
Enter the first integer a := 7
Line 725 ⟶ 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 731 ⟶ 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 759 ⟶ 2,257:
} catch(IOException e) { }
}
}</langsyntaxhighlight>
 
=={{header|JavaScript}}==
<langsyntaxhighlight lang="javascript">
// Using type coercion
function compare(a, b) {
Line 785 ⟶ 2,284:
} else {
// "1" and 1 are an example of this as the first is type string and the second is type number
print(a + "{" + (typeof a) + "} and " + b + "{" + (typeof b) + "} are not of the same type 4andand cannot be compared.");
}
}
</syntaxhighlight>
</lang>
 
=={{header|Joy}}==
<langsyntaxhighlight lang="joy">#!/usr/local/bin/joy.exe
DEFINE
prompt == "Please enter a number and <Enter>: " putchars;
Line 797 ⟶ 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|Liberty BASICjq}}==
<syntaxhighlight lang="jq"># compare/0 compares the first two items if they are numbers,
Verbose version:
# otherwise an "uncomparable" message is emitted.
<lang lb>input "Enter an integer for a. ";a
input "Enter an integer for b. ";b
 
def compare:
'a=int(a):b=int(b) ???
def english:
print "Conditional evaluation."
if a<b then print "a<bif ".[0] ;< a.[1] ;then "less < than" ; b
if a=b then print "a=belif ".[0] ;== a.[1] ;then "equal = to" ; b
else "greater than"
if a>b then print "a>b " ; a ; " > " ; b
end;
if (.[0]|type) == "number" and (.[1]|type) == "number" then
"\(.[0]) is \(english) \(.[1])"
else
"\(.[0]) is uncomparable to \(.[1])"
end ;
 
compare</syntaxhighlight>
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>
 
Examples;
Concise:
<syntaxhighlight lang="jq">
<lang lb>input "Enter an integer for a. ";a
$ jq -s -r -f Integer_comparison.jq
input "Enter an integer for b. ";b
1 2
1 is less than 2
 
$ jq -s -r -f Integer_comparison.jq
for i = 1 to 3
1 "a"
op$=word$("< = >", i)
1 is uncomparable to a
if eval("a"+op$+"b") then print "a"+op$+"b " ; a;" ";op$;" ";b
</syntaxhighlight>
next
 
</lang>
=={{header|Julia}}==
<syntaxhighlight lang="julia">function compare()
int1 = readline(stdin)
int2 = readline(stdin)
print(int1, " is ",
int1 < int2 ? "less than " :
int1 == int2 ? "equal to " :
int1 > int2 ? "greater than " :
"uncomparable to",
int2)
end
</syntaxhighlight>{{out}}
<pre>julia> compare()
3
5
3 is less than 5
</pre>
 
=={{header|Kotlin}}==
<syntaxhighlight lang="kotlin">fun main() {
val n1 = readLine()!!.toLong()
val n2 = readLine()!!.toLong()
println(when {
n1 < n2 -> "$n1 is less than $n2"
n1 > n2 -> "$n1 is greater than $n2"
n1 == n2 -> "$n1 is equal to $n2"
else -> ""
})
}</syntaxhighlight>
 
=={{header|Lambdatalk}}==
<syntaxhighlight lang="scheme">
{def compare
{lambda {:a :b}
{if {< :a :b}
then :a is lesser than :b
else {if {> :a :b}
then :a is greater than :b
else :a is equal to :b}}}}
 
{compare 1 2}
-> 1 is lesser than 2
 
{compare 2 1}
-> 2 is greater than 1
 
{compare 1 1}
-> 1 is equal to 1
</syntaxhighlight>
 
=={{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}}==
<syntaxhighlight lang="lasso">local(
number1 = integer(web_request -> param('number1')),
number2 = integer(web_request -> param('number2'))
)
 
#number1 < #number2 ? 'Number 1 is less than Number 2' | 'Number 1 is not less than Number 2'
'<br />'
#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'</syntaxhighlight>
 
{{out}}
<pre>// with input of 2 & 2
Number 1 is not less than Number 2
Number 1 is the same as Number 2
Number 1 is not greater than Number 2</pre>
 
=={{header|LIL}}==
<syntaxhighlight lang="tcl">print "Enter two numbers separated by space"
set rc [readline]
set a [index $rc 0]
set b [index $rc 1]
 
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"}</syntaxhighlight>
 
=={{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:
<syntaxhighlight 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</syntaxhighlight>
 
=={{header|LiveCode}}==
<syntaxhighlight lang="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
put item 2 of it into num2
if isnumber(num1) and isnumber(num2) then
if num1 < num2 then answer num1 && "is less than" && num2
if num1 is num2 then answer num1 && "is equal to" && num2
if num1 > num2 then answer num1 && "is greater than" && num2
 
-- alternative is to use switch case construct
switch
case (num1 < num2)
answer num1 && "is less! than" && num2; break
case (num1 > num2)
answer num1 && "is greater! than" && num2; break
case (num1 = num2)
answer num1 && "equal! to" && num2
end switch
end if
end if</syntaxhighlight>
 
=={{header|LLVM}}==
Line 851 ⟶ 2,471:
{{libheader|cstdlib}}
 
<langsyntaxhighlight lang="llvm">; ModuleID = 'test.o'
;e means little endian
;p: { pointer size : pointer abi : preferred alignment for pointers }
Line 942 ⟶ 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]].
 
 
=={{header|LSE}}==
 
==={{header|avec SI}}===
<syntaxhighlight lang="lse">(* Comparaison de deux entiers en LSE (LSE-2000) *)
ENTIER A, B
LIRE ['Entrez un premier entier:',U] A
LIRE ['Entrez un second entier:',U] B
SI A < B ALORS
AFFICHER [U,' est plus petit que ',U,/] A, B
FIN SI
SI A = B ALORS
AFFICHER [U,' est égale à ',U,/] A, B
FIN SI
SI A > B ALORS
AFFICHER [U,' est plus grand que ',U,/] A, B
FIN SI</syntaxhighlight>
 
==={{header|avec ÉVALUER}}===
<syntaxhighlight lang="lse">(* Comparaison de deux entiers en LSE (LSE-2000) *)
ENTIER A, B
LIRE ['Entrez un premier entier:',U] A
LIRE ['Entrez un second entier:',U] B
EVALUER .VRAI.
QUAND A < B
AFFICHER [U,' est plus petit que ',U,/] A, B
QUAND A = B
AFFICHER [U,' est égale à ',U,/] A, B
QUAND AUTRE
AFFICHER [U,' est plus grand que ',U,/] A, B
FIN EVALUER</syntaxhighlight>
 
==={{header|avec SI..IS}}===
<syntaxhighlight lang="lse">(* Comparaison de deux entiers en LSE (LSE-2000) *)
ENTIER A, B
LIRE ['Entrez un premier entier:',U] A
LIRE ['Entrez un second entier:',U] B
AFFICHER [U, U, U, /] A, \
SI A < B ALORS ' est plus petit que ' SINON \
SI A = B ALORS ' est égale à ' SINON \
SI A > B ALORS ' est plus grand que ' SINON '?' IS IS IS, B
</syntaxhighlight>
 
=={{header|LSE64}}==
<syntaxhighlight lang="lse64">over : 2 pick
2dup : over over
 
compare : 2dup = then " equals"
compare : 2dup < then " is less than"
compare : 2dup > then " is more than"
 
show : compare rot , sp ,t sp , nl</syntaxhighlight>
 
=={{header|Lua}}==
<langsyntaxhighlight lang="lua">print('Enter the first number: ')
a = tonumber(io.stdin:read())
print('Enter the second number: ')
Line 960 ⟶ 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|LSE64Maple}}==
<syntaxhighlight lang="maple">CompareNumbers := proc( )
<lang lse64>over : 2 pick
local a, b;
2dup : over over
printf( "Enter a number:> " );
a := parse(readline());
printf( "Enter another number:> " );
b := parse(readline());
if a < b then
printf("The first number is less than the second");
elif a = b then
printf("The first number is equal to the second");
elif a > b then
printf("The first number is greater than the second");
end if;
end proc:
 
CompareNumbers();</syntaxhighlight>
compare : 2dup = then " equals"
compare : 2dup < then " is less than"
compare : 2dup > then " is more than"
 
=={{header|Mathematica}} / {{header|Wolfram Language}}==
show : compare rot , sp ,t sp , nl</lang>
<syntaxhighlight lang="mathematica">a=Input["Give me the value for a please!"];
=={{header|Mathematica}}==
<lang 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 990 ⟶ 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 1,011 ⟶ 2,694:
message decimal a1 & " is equal to " & decimal a2
fi;
end</langsyntaxhighlight>
 
=={{header|min}}==
{{works with|min|0.19.3}}
<syntaxhighlight lang="min">"$1 is $2 $3."
("Enter an integer" ask) 2 times over over
(
((>) ("greater than"))
((<) ("less than"))
((==) ("equal to"))
) case
' append prepend % print</syntaxhighlight>
 
=={{header|MiniScript}}==
<syntaxhighlight lang="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</syntaxhighlight>
 
=={{header|МК-61/52}}==
<syntaxhighlight lang="text">- ЗН С/П</syntaxhighlight>
 
''Input:'' a ^ b
 
''Output:'' 1 (a > b) | -1 (a < b) | 0 (a = b)
 
=={{header|ML/I}}==
This reads the two numbers from 'standard input' or similar, and outputs the results to 'standard output' or equivalent. 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''.
 
<langsyntaxhighlight MLlang="ml/Ii">"" Integer comparison
"" assumes macros on input stream 1, terminal on stream 2
MCSKIP MT,<>
Line 1,033 ⟶ 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 1,121 ⟶ 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 1,142 ⟶ 2,851:
 
=={{header|Modula-2}}==
<langsyntaxhighlight lang="modula2">MODULE IntCompare;
 
IMPORT InOut;
Line 1,163 ⟶ 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 1,183 ⟶ 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 1,195 ⟶ 2,905:
IF A>B WRITE !,A," is greater than ",B
KILL A,B
QUIT</langsyntaxhighlight>
{{out}}
Output:<pre>USER>d INTCOMP^ROSETTA
<pre>USER>d INTCOMP^ROSETTA
Enter an integer to test: 43
Line 1,211 ⟶ 2,922:
Enter another integer: 2
2 is equal to 2</pre>
 
=={{header|Nanoquery}}==
<syntaxhighlight lang="nanoquery">print "enter first integer: "
first = int(input())
print "enter second integer: "
second = int(input())
 
if first = second
println "the two integers are equal"
else if first < second
println first + " is less than " + second
else if first > second
println first + " is greater than " + second
end</syntaxhighlight>
 
=={{header|Nemerle}}==
Showing both the use of comparison operators and the .Net Int32.CompareTo() method.
<langsyntaxhighlight Nemerlelang="nemerle">using System;
using System.Console;
 
Line 1,244 ⟶ 2,969:
}
}
}</langsyntaxhighlight>
 
=={{header|NetRexx}}==
<syntaxhighlight lang="netrexx">/* NetRexx */
options replace format comments java crossref symbols nobinary
 
numL = 0
numR = 0
loop label running forever
say 'Provide two integers [or anything else to stop]:'
parse ask numL numR .
if \numL.datatype('w') | \numR.datatype('w') then leave running
if numL < numR then say numL 'is less than' numR
if numL = numR then say numL 'is equal to' numR
if numL > numR then say numL 'is greater than' numR
end running
 
return
</syntaxhighlight>
 
=={{header|NewLISP}}==
<syntaxhighlight lang="newlisp">
(print "Please enter the first number: ")
(set 'A (int (read-line)))
(print "Please enter the second number: ")
(set 'B (int (read-line)))
(println
"The first one is "
(cond
((> A B) "greater than")
((= A B) "equal to")
(true "less than"))
" the second.")
</syntaxhighlight>
 
=={{header|Nim}}==
<syntaxhighlight lang="nim">import rdstdin, strutils
var a = parseInt(readLineFromStdin "Enter value of a: ")
var b = parseInt(readLineFromStdin "Enter value of b: ")
 
if a < b:
echo "a is less than b"
elif a > b:
echo "a is greater than b"
elif a == b:
echo "a is equal to b"</syntaxhighlight>
 
=={{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 1,271 ⟶ 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 1,293 ⟶ 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 1,321 ⟶ 3,100:
Out.Ln;
END;
END Compare.</langsyntaxhighlight>
 
=={{header|Objeck}}==
<langsyntaxhighlight lang="objeck">
bundle Default {
class IntCompare {
Line 1,345 ⟶ 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 1,357 ⟶ 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 1,370 ⟶ 3,149:
elseif (a < b)
disp("a less than b");
endif</langsyntaxhighlight>
 
=={{header|Oforth}}==
 
<syntaxhighlight lang="oforth">import: console
 
: cmpInt
| a b |
doWhile: [ System.Console askln asInteger dup ->a isNull ]
doWhile: [ System.Console askln asInteger dup ->b isNull ]
 
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 ] ;</syntaxhighlight>
 
=={{header|Ol}}==
<syntaxhighlight lang="scheme">
(define (compare a b)
(cond ((< a b) "A is less than B")
((> a b) "A is greater than B")
((= a b) "A equals B")))
 
(print (compare 1 2))
; ==> A is less than B
 
(print (compare 2 2))
; ==> A equals B
 
(print (compare 3 2))
; ==> A is greater than B
 
; manual user input:
(print (compare (read) (read)))
</syntaxhighlight>
 
=={{header|Oz}}==
<langsyntaxhighlight lang="oz">functor
import
Application(exit)
Line 1,400 ⟶ 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 1,423 ⟶ 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 1,430 ⟶ 3,242:
Separate tests for less than, greater than, and equals
 
<langsyntaxhighlight lang="perl">sub test_num {
my $f = shift;
my $s = shift;
Line 1,442 ⟶ 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|Perl 6Phix}}==
{{libheader|Phix/basics}}
{{works with|Rakudo|#22 "Thousand Oaks"}}
<!--<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: #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: #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>
<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>
<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>
<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>
<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>
<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>
<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>
<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}}==
<lang perl6>my Int $a = floor $*IN.get;
<syntaxhighlight lang="Phixmonti">/# Rosetta Code problem: http://rosettacode.org/wiki/Integer_comparison
my Int $b = floor $*IN.get;
by Galileo, 10/2022 #/
 
"Enter first number: " input tonum nl
if $a < $b {
"Enter second number: " input tonum nl
say 'Less';
}
elsif $a > $b {
say 'Greater';
}
elsif $a == $b {
say 'Equal';
}</lang>
 
over over -
With <code>cmp</code>:
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}}==
<lang perl6>say <Less Equal Greater>[($a cmp $b) + 1];</lang>
 
<syntaxhighlight lang="phl">module intergertest;
 
extern printf;
extern scanf;
 
@Integer main [
var a = 0;
var b = 0;
scanf("%i %i", ref (a), ref (b));
if (a < b)
printf("%i is less than %i\n", a::get, b::get);
if (a == b)
printf("%i is equal to %i\n", a::get, b::get);
if (a > b)
printf("%i is greater than %i\n", a::get, b::get);
return 0;
]</syntaxhighlight>
 
=={{header|PHP}}==
<langsyntaxhighlight lang="php"><?php
 
echo "Enter an integer [int1]: ";
Line 1,504 ⟶ 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
(let (A (read) B (read))
(prinl
"The first one is "
Line 1,518 ⟶ 3,370:
((= A B) "equal to")
(T "less than") )
" the second." ) ) )</langsyntaxhighlight>
{{out}}
Output:
<pre>Please enter two values: 4 3
The first one is greater than the second.</pre>
 
=={{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 1,540 ⟶ 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 1,553 ⟶ 3,405:
if a < b then
put skip list ('The second number is greater than the first');
</syntaxhighlight>
</lang>
 
=={{header|Plain English}}==
<syntaxhighlight lang="plainenglish">To run:
Start up.
Write "Enter the first number: " to the console without advancing.
Read a first number from the console.
Write "Enter the second number: " to the console without advancing.
Read a second number from the console.
If the first number is less than the second number, write "Less than!" to the console.
If the first number is the second number, write "Equal!" to the console.
If the first number is greater than the second number, write "Greater than!" to the console.
Wait for the escape key.
Shut down.</syntaxhighlight>
 
=={{header|Pop11}}==
<langsyntaxhighlight lang="pop11">;;; Comparison procedure
define compare_integers(x, y);
if x > y then
Line 1,572 ⟶ 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 1,583 ⟶ 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 = int(raw_inputinput('Enter value of a: '))
b = int(raw_inputinput('Enter value of b: '))
 
if a < b:
Line 1,615 ⟶ 3,461:
print 'a is greater than b'
elif a == b:
print 'a is equal to b'</langsyntaxhighlight>
 
(Note: in Python3 ''raw_inputinput()'' will become ''int(input().)'').
 
An alternative implementation could use a Python dictionary to house a small dispatch table to be indexed by the results of the built-in ''cmp()'' function. ''cmp()'' returns a value suitable for use as a comparison function in a sorting algorithm: -1, 0 or 1 for <, = or > respectively. Thus we could use:
 
{{works with|Python|2.x only, not 3.x}}
<langsyntaxhighlight Pythonlang="python">#!/usr/bin/env python
import sys
try:
a = int(raw_inputinput('Enter value of a: '))
b = int(raw_inputinput('Enter value of b: '))
except (ValueError, EnvironmentError), err:
print sys.stderr, "Erroneous input:", err
Line 1,636 ⟶ 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 1,651 ⟶ 3,527:
} else if ( a == b ) { # could be simply else of course...
print("a and b are the same")
}</langsyntaxhighlight>
 
=={{header|Racket}}==
<syntaxhighlight lang="racket">#lang racket
(define (compare-two-ints a b)
(define compared
(cond ((> a b) "is greated than")
((= a b) "equals")
((< a b) "is lesser than")))
(format "~a ~a ~a" a compared b))
(compare-two-ints (read) (read))</syntaxhighlight>
 
=={{header|Raku}}==
(formerly Perl 6)
<syntaxhighlight lang="raku" line>my $a = prompt("1st int: ").floor;
my $b = prompt("2nd int: ").floor;
 
if $a < $b {
say 'Less';
}
elsif $a > $b {
say 'Greater';
}
elsif $a == $b {
say 'Equal';
}</syntaxhighlight>
 
With <code><=></code>:
 
<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:
 
<syntaxhighlight lang="raku" line>say prompt("1st int: ") <=> prompt("2nd int: ");</syntaxhighlight>
 
=={{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}}==
<syntaxhighlight lang="raven">"Enter the first number: " print
expect trim 1.1 prefer as $a
"Enter the second number: " print
expect trim 1.1 prefer as $b
$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</syntaxhighlight>
 
=={{header|REBOL}}==
<syntaxhighlight lang="rebol">
<lang REBOL>
REBOL [
Title: "Comparing Two Integers"
Author: oofoe
Date: 2009-12-04
URL: http://rosettacode.org/wiki/Comparing_two_integers
]
Line 1,671 ⟶ 3,602:
]
print [a "is" case relation b]
</syntaxhighlight>
</lang>
 
==={{header|RetroRelation}}===
TakingThere theis no input, so numbers fromhave to be given thein stack:code
<syntaxhighlight lang="relation">
set a = 15
set b = 21
if a > b
' a is bigger than b
else
if b > a
' b is bigger than a
else
' a is equal to b
end if
end if
</syntaxhighlight>
 
=={{header|Red}}==
<lang Retro>: example ( ab- )
{{trans|REBOL}}
cons
<syntaxhighlight lang="rebol">Red [
[ do > [ "A > B\n" puts ] ifTrue ]
Title: "Comparing Two Integers"
[ do < [ "A < B\n" puts ] ifTrue ]
URL: http://rosettacode.org/wiki/Comparing_two_integers
[ do = [ "A = B\n" puts ] ifTrue ] tri ;</lang>
Date: 2021-10-25
]
 
a: to-integer ask "First integer? " b: to-integer ask "Second integer? "
Or, to parse for numbers:
 
relation: [
<lang Retro>: example ( ab- )
a < b "less than"
getToken getToken &toNumber bi@ cons
[ do >a [= b "Aequal > B\nto" puts ] ifTrue ]
[ do <a [> b "Agreater < B\nthan" puts ] ifTrue ]
]
[ do = [ "A = B\n" puts ] ifTrue ] tri ;</lang>
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:
 
<syntaxhighlight lang="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 ;</syntaxhighlight>
 
=={{header|REXX}}==
<syntaxhighlight lang REXX="rexx">/*REXX program prompts for two integers, compares 'emthem, telland results. displays the results.*/
numeric digits 2000 /*for the users that really go ka─razy.*/
a=getInt('─────── Please enter your first integer:') /*get an integer.*/
@=copies('─', 20) /*eyeball catcher for the user's eyen. */
b=getInt('─────── Please enter your second integer:') /*get another int*/
a=getInt(@ 'Please enter your 1st integer:') /*obtain the 1st integer from the user.*/
b=getInt(@ 'Please enter your 2nd integer:') /* " " 2nd " " " " */
say
if a<b then say @ a ' is less thenthan ' b
if a=b then say @ a ' is equal to ' b
if a>b then say @ a ' is greater than ' b
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
/*──────────────────────────────────GETINT subroutine───────────────────*/
getInt: procedure do forever; say /*routine getskeep anprompting intthe fromuser until CBLF.success*/
say arg(1) /*¬geeks:display the prompt Carbon-Basedmessage Lifeto Form.console*/
do forever parse pull x /*keepobtain prompting untilX, success. and keep its case intact.*/
say; say arg(1) /*display the prompt message. */select
parse pull x when x='' /*getthen X,call andserr keep"No itsargument casewas intact*/entered."
when words(x)>1 then call serr 'Too many arguments entered.' x
select
when x='' when \datatype(x, 'N') then call serr "Argument isn'Nothingt wasnumeric:" entered.' x
when words(x)>1 when \datatype(x, 'W') then call serr "Argument isn'Toot manyan argumentsinteger:" entered.' x
otherwise return x /* [↑] Eureka! Return # to invoker. */
when \datatype(x,'N') then call serr "Argument isn't numeric:" x
end /*select*/
when \datatype(x,'W') then call serr "Argument isn't an integer:" x
otherwise end return x /*eureka! return X to invoker. forever*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
end /*select*/
serr: say @ '***error*** ' arg(1); say @ "Please try again."; return</syntaxhighlight>
end /*forever*/
{{out|output|text=&nbsp; (shows user input and computer program output together):}}
/*──────────────────────────────────SERR subroutine─────────────────────*/
<pre>
serr: say; say '*** error! ***'; say arg(1); say "Try again."; return
──────────────────── Please enter your 1st integer:
</lang>
bupkis ◄■■■■■■■■■■■■■■■ user input.
'''output'''
──────────────────── ***error*** Argument isn't numeric: bupkis
<pre style="height:30ex;overflow:scroll">
──────────────────── Please try again.
─────── Please enter your first integer:
bupkis
 
──────────────────── Please enter your 1st integer:
***error!*** Argument isn't numeric: bupkis
1 2 ◄■■■■■■■■■■■■■■■ user input.
Try again.
──────────────────── ***error*** Too many arguments entered.
──────────────────── Please try again.
 
─────────────────────────── Please enter your first1st integer:
5.77 ◄■■■■■■■■■■■■■■■ user input.
3 and 4
──────────────────── ***error*** Argument isn't an integer: 5.77
──────────────────── Please try again.
 
──────────────────── Please enter your 1st integer:
***error!*** Too many arguments entered.
-6 ◄■■■■■■■■■■■■■■■ user input.
Try again.
 
─────────────────────────── Please enter your first2nd integer:
19.00 ◄■■■■■■■■■■■■■■■ user input.
5.6
 
──────────────────── -6 is less than 19.00
***error!*** Argument isn't an integer: 5.6
</pre>
Try again.
 
=={{header|Ring}}==
─────── Please enter your first integer:
<syntaxhighlight lang="ring">
+6
Func Compare a,b
if a < b
See "A is less than B"
but a > b
See "A is more than B"
else
See "A equals B"
ok
</syntaxhighlight>
 
=={{header|Rockstar}}==
─────── Please enter your second integer:
17
 
Minimized Rockstar:
+6 is less then 17
 
<syntaxhighlight lang="rockstar">
(Get two numbers from user)
Listen to Number One
Listen to Number Two
(Check if n1 > n2)
If Number One is greater than Number Two
Say "The first is greater than the second"
 
(Check if n1 = n2)
If Number One is Number Two
Say "The Numbers are equal"
 
(Check if n1 < n2)
If Number One is less than Number Two
Say "The first is less than the second"
</syntaxhighlight>
 
Idiomatic version:
<syntaxhighlight lang="rockstar">
Listen to your soul
Listen to my words
 
If your soul is my words,
Say "They're the same"
 
If your soul is stronger than my words,
Say "The first was bigger"
 
If your soul is smaller than my words,
Say "The second was bigger".
</syntaxhighlight>
 
=={{header|RPG}}==
Two integers are passed as parameters. Because the command line casts numeric literals as packed(15,5), calling from the command line requires the user to specify the 8 nybbles in hexadecimal form:
 
CALL rc_intcmp (x'00000000' x'00000001')
 
<syntaxhighlight lang="rpg">
h dftactgrp(*no)
 
d pi
d integer1 10i 0
d integer2 10i 0
 
d message s 50a
 
if integer1 < integer2;
message = 'Integer 1 is less than integer 2';
endif;
 
if integer1 > integer2;
message = 'Integer 1 is greater than integer 2';
endif;
 
if integer1 = integer2;
message = 'Integer 1 is equal to integer 2';
endif;
 
dsply message;
*inlr = *on;
</syntaxhighlight>
 
=={{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>
 
Line 1,748 ⟶ 3,815:
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 1,764 ⟶ 3,831:
when 0; puts "#{a} is equal to #{b}"
when +1; puts "#{a} is greater than #{b}"
end</langsyntaxhighlight>
 
Example '''input''' and output:
<pre>
 
$ '''ruby compare.rb'''
enter a value for a: '''5'''
Line 1,776 ⟶ 3,843:
enter a value for b: '''dog'''
0 is equal to 0
</pre>
 
----
Line 1,781 ⟶ 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 1,804 ⟶ 3,872:
 
# I hope you can figure this out
puts "#{a} is #{dispatch[a<=>b]} #{b}"</langsyntaxhighlight>
 
=={{header|Rust}}==
Reading from stdin into a string is cumbersome at the moment, but convenience functions will be implemented in the future.
<syntaxhighlight lang="rust">use std::io::{self, BufRead};
 
fn main() {
 
let mut reader = io::stdin();
=={{header|Run BASIC}}==
let mut buffer = String::new();
<lang runbasic>input "1st number:"; n1
let mut lines = reader.lock().lines().take(2);
input "2nd number:"; n2
let nums: Vec<i32>= lines.map(|string|
 
string.unwrap().trim().parse().unwrap()
if n1 < n2 then print "1st number ";n1;" is less than 2nd number";n2
).collect();
if n1 > n2 then print "1st number ";n1;" is greater than 2nd number";n2
let a: i32 = nums[0];
if n1 = n2 then print "1st number ";n1;" is equal to 2nd number";n2</lang>
let b: i32 = nums[1];
if a < b {
println!("{} is less than {}" , a , b)
} else if a == b {
println!("{} equals {}" , a , b)
} else if a > b {
println!("{} is greater than {}" , a , b)
};
}</syntaxhighlight>
 
=={{header|SAS}}==
<langsyntaxhighlight lang="sas">/* Showing operators and their fortran-like equivalents. Note that ~= and ^= both mean "different" */
data _null_;
input a b;
Line 1,839 ⟶ 3,919:
1 1
;
run;</langsyntaxhighlight>
 
=={{header|Scala}}==
<langsyntaxhighlight lang="scala">object IntCompare {
def main(args: Array[String]): Unit = {
val a=Console.readInt
Line 1,853 ⟶ 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 1,885 ⟶ 3,965:
writeln(a <& " is greater than " <& b);
end if;
end func;</langsyntaxhighlight>
 
=={{header|SenseTalk}}==
 
<syntaxhighlight lang="sensetalk">Ask "Provide Any Number"
 
Put It into A
 
Ask " Provide Another Number"
 
Put it into B
 
if A is less than B
Put A&" Is less than " &B
end if
 
if A is greater than B
Put A& " is Greater than " &B
end if
 
If A is Equal to B
Put A& " is Equal to " &B
End If</syntaxhighlight>
 
=={{header|Sidef}}==
<syntaxhighlight lang="ruby">var a = read("a: ", Number);
var b = read("b: ", Number);
 
if (a < b) {
say 'Lower';
}
elsif (a == b) {
say 'Equal';
}
elsif (a > b) {
say 'Greater';
}</syntaxhighlight>
{{out}}
<pre>
% sidef numcmp.sf
a: 21
b: 42
Lower</pre>
 
=={{header|Slate}}==
<langsyntaxhighlight lang="slate">[ |:a :b |
 
( a > b ) ifTrue: [ inform: 'a greater than b\n' ].
Line 1,895 ⟶ 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 1,910 ⟶ 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 1,917 ⟶ 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}}==
<syntaxhighlight lang="sparkling">let a = 13, b = 37;
if a < b {
print("a < b");
} else if a > b {
print("a > b");
} else if a == b {
print("a == b");
} else {
print("either a or b or both are NaN");
}</syntaxhighlight>
 
=={{header|SQL}}==
{{works with|Oracle}}
<syntaxhighlight lang="sql">
drop table test;
 
create table test(a integer, b integer);
 
insert into test values (1,2);
 
insert into test values (2,2);
 
insert into test values (2,1);
 
select to_char(a)||' is less than '||to_char(b) less_than
from test
where a < b;
 
select to_char(a)||' is equal to '||to_char(b) equal_to
from test
where a = b;
 
select to_char(a)||' is greater than '||to_char(b) greater_than
from test
where a > b;
</syntaxhighlight>
 
<pre>
SQL> SQL> 2 3
LESS_THAN
--------------------------------------------------------------------------------
1 is less than 2
 
SQL> SQL> 2 3
EQUAL_TO
--------------------------------------------------------------------------------
2 is equal to 2
 
SQL> SQL> 2 3
GREATER_THAN
--------------------------------------------------------------------------------
2 is greater than 1
</pre>
 
=={{header|SQL PL}}==
{{works with|Db2 LUW}}
With SQL only:
<syntaxhighlight lang="sql pl">
CREATE TABLE TEST (
VAL1 INT,
VAL2 INT
);
INSERT INTO TEST (VAL1, VAL2) VALUES
(1, 2),
(2, 2),
(2, 1);
SELECT
CASE
WHEN VAL1 < VAL2 THEN VAL1 || ' less than ' || VAL2
WHEN VAL1 = VAL2 THEN VAL1 || ' equal to ' || VAL2
WHEN VAL1 > VAL2 THEN VAL1 || ' greater than ' || VAL2
END COMPARISON
FROM TEST;
</syntaxhighlight>
Output:
<pre>
db2 -t
db2 => CREATE TABLE TEST (
db2 (cont.) => VAL1 INT,
db2 (cont.) => VAL2 INT
db2 (cont.) => );
DB20000I The SQL command completed successfully.
db2 => INSERT INTO TEST (VAL1, VAL2) VALUES
db2 (cont.) => (1, 2),
db2 (cont.) => (2, 2),
db2 (cont.) => (2, 1);
DB20000I The SQL command completed successfully.
db2 => SELECT
db2 (cont.) => CASE
db2 (cont.) => WHEN VAL1 < VAL2 THEN VAL1 || ' less than ' || VAL2
db2 (cont.) => WHEN VAL1 = VAL2 THEN VAL1 || ' equal to ' || VAL2
db2 (cont.) => WHEN VAL1 > VAL2 THEN VAL1 || ' greater than ' || VAL2
db2 (cont.) => END COMPARISON
db2 (cont.) => FROM TEST;
 
COMPARISON
-----------------------------------
1 less than 2
2 equal to 2
2 greater than 1
 
3 record(s) selected.
</pre>
{{works with|Db2 LUW}} version 9.7 or higher.
With SQL PL:
<syntaxhighlight lang="sql pl">
--#SET TERMINATOR @
 
SET serveroutput ON @
 
CREATE PROCEDURE COMPARISON (IN VAL1 INT, IN VAL2 INT)
BEGIN
IF (VAL1 < VAL2) THEN
CALL DBMS_OUTPUT.PUT_LINE(VAL1 || ' less than ' || VAL2);
ELSEIF (VAL1 = VAL2) THEN
CALL DBMS_OUTPUT.PUT_LINE(VAL1 || ' equal to ' || VAL2);
ELSEIF (VAL1 > VAL2) THEN
CALL DBMS_OUTPUT.PUT_LINE(VAL1 || ' greater than ' || VAL2);
END IF;
END @
CALL COMPARISON(1, 2) @
CALL COMPARISON(2, 2) @
CALL COMPARISON(2, 1) @
</syntaxhighlight>
Output:
<pre>
db2 -td@
db2 => SET serveroutput ON @
DB20000I The SET SERVEROUTPUT command completed successfully.
db2 => CREATE PROCEDURE COMPARISON (IN VAL1 INT, IN VAL2 INT)
db2 (cont.) => BEGIN
db2 (cont.) => IF (VAL1 < VAL2) THEN
db2 (cont.) => CALL DBMS_OUTPUT.PUT_LINE(VAL1 || ' less than ' || VAL2);
db2 (cont.) => ELSEIF (VAL1 = VAL2) THEN
db2 (cont.) => CALL DBMS_OUTPUT.PUT_LINE(VAL1 || ' equal to ' || VAL2);
db2 (cont.) => ELSEIF (VAL1 > VAL2) THEN
db2 (cont.) => CALL DBMS_OUTPUT.PUT_LINE(VAL1 || ' greater than ' || VAL2);
db2 (cont.) => END IF;
db2 (cont.) => END @
DB20000I The SQL command completed successfully.
db2 => CALL COMPARISON(1, 2) @
Return Status = 0
 
1 less than 2
db2 => CALL COMPARISON(2, 2) @
Return Status = 0
 
2 equal to 2
db2 => CALL COMPARISON(2, 1) @
 
Return Status = 0
 
2 greater than 1
</pre>
 
=={{header|SSEM}}==
The SSEM only provides one conditional operation: <tt>011 Test</tt>, which causes execution to skip one instruction if the value in the accumulator is negative. We can use this to implement conditional tests along the lines of the following pseudocode:
<pre> accumulator := a - b;
if accumulator >= 0 then
(* a is not less than b, so *)
goto next_test
else
goto less;
next_test: accumulator := accumulator - 1;
if accumulator >= 0 then
goto greater
else
(* a and b are equal *)
accumulator := 0;
halt;
greater: accumulator := 1;
halt;
less: accumulator := -1;
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.
<syntaxhighlight lang="ssem">10101000000000100000000000000000 0. -21 to c
10101000000001100000000000000000 1. c to 21
10101000000000100000000000000000 2. -21 to c
01101000000000010000000000000000 3. Sub. 22
00000000000000110000000000000000 4. Test
00001000000001000000000000000000 5. Add 16 to CI
00101000000000000000000000000000 6. 20 to CI
00001000000000010000000000000000 7. Sub. 16
00000000000000110000000000000000 8. Test
11001000000000000000000000000000 9. 19 to CI
10001000000000100000000000000000 10. -17 to c
00000000000001110000000000000000 11. Stop
01001000000000100000000000000000 12. -18 to c
00000000000001110000000000000000 13. Stop
00001000000000100000000000000000 14. -16 to c
00000000000001110000000000000000 15. Stop
10000000000000000000000000000000 16. 1
00000000000000000000000000000000 17. 0
11111111111111111111111111111111 18. -1
11010000000000000000000000000000 19. 11
10110000000000000000000000000000 20. 13</syntaxhighlight>
 
=={{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 1,940 ⟶ 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}}==
<syntaxhighlight lang="swift">import Cocoa
 
var input = NSFileHandle.fileHandleWithStandardInput()
 
println("Enter two integers separated by a space: ")
 
let data = input.availableData
let stringArray = NSString(data: data, encoding: NSUTF8StringEncoding)?.componentsSeparatedByString(" ")
var a:Int!
var b:Int!
if (stringArray?.count == 2) {
a = stringArray![0].integerValue
b = stringArray![1].integerValue
}
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)")}</syntaxhighlight>
{{out}}
<pre>
Enter two integers separated by a space:
234 233
234 is greater than 233</pre>
 
=={{header|Tcl}}==
Line 1,951 ⟶ 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 1,958 ⟶ 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 1,964 ⟶ 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 1,971 ⟶ 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 1,979 ⟶ 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-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 2,005 ⟶ 4,334:
1 1 compare-integers
2 1 compare-integers
1 2 compare-integers</langsyntaxhighlight>
 
=={{header|TUSCRIPT}}==
<langsyntaxhighlight lang="tuscript">
$$ MODE TUSCRIPT
 
Line 2,019 ⟶ 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 2,026 ⟶ 4,355:
{{works with|ksh93}}
 
<langsyntaxhighlight lang="bash">#!/bin/ksh
# tested with ksh93s+
 
Line 2,047 ⟶ 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 2,053 ⟶ 4,382:
{{works with|pdksh}}
 
<langsyntaxhighlight lang="bash">#!/bin/ksh
# tested with pdksh
 
Line 2,072 ⟶ 4,401:
fi
 
exit 0</langsyntaxhighlight>
 
----
Line 2,078 ⟶ 4,407:
{{works with|Bash}}
 
<langsyntaxhighlight lang="bash">read -p "Enter two integers: " a b
 
if [ $a -gt $b ]; then comparison="greater than"
Line 2,086 ⟶ 4,415:
fi
 
echo "${a} is ${comparison} ${b}"</langsyntaxhighlight>
 
=={{header|Ursa}}==
<syntaxhighlight lang="ursa">decl int first second
out "enter first integer: " console
set first (in int console)
out "enter second integer: " console
set second (in int console)
 
if (= first second)
out "the two integers are equal" endl console
end if
if (< first second)
out first " is less than " second endl console
end if
if (> first second)
out first " is greater than " second endl console
end if</syntaxhighlight>
 
=={{header|V}}==
<langsyntaxhighlight lang="v">[compare
[ [>] ['less than' puts]
[<] ['greater than' puts]
Line 2,100 ⟶ 4,446:
less than
|2 2 compare
is equal</langsyntaxhighlight>
 
=={{header|Vala}}==
<langsyntaxhighlight lang="vala">
void main(){
int a;
Line 2,120 ⟶ 4,467:
stdout.printf("%d is greater than %d\n", a, b);
}
</syntaxhighlight>
</lang>
 
=={{header|VBScriptWart}}==
<syntaxhighlight lang="wart">a <- (read)
Based on the BASIC
b <- (read)
=====Implementation=====
prn (if (a < b)
<lang vb>
: "a is less than b"
option explicit
(a > b)
: "a is greater than b"
:else
: "a equals b")</syntaxhighlight>
 
=={{header|Wren}}==
function eef( b, r1, r2 )
<syntaxhighlight lang="wren">import "io" for Stdin, Stdout
if b then
eef = r1
else
eef = r2
end if
end function
 
System.print("Enter anything other than a number to quit at any time.\n")
dim a, b
while (true) {
wscript.stdout.write "First integer: "
System.write(" First number : ")
a = cint(wscript.stdin.readline) 'force to integer
Stdout.flush()
var a = Num.fromString(Stdin.readLine())
if (!a) break
System.write(" Second number : ")
Stdout.flush()
var b = Num.fromString(Stdin.readLine())
if (!b) break
var s = (a-b).sign
if (s < 0) {
System.print(" %(a) < %(b)")
} else if (s == 0) {
System.print(" %(a) == %(b)")
} else {
System.print(" %(a) > %(b)")
}
System.print()
}</syntaxhighlight>
 
{{out}}
wscript.stdout.write "Second integer: "
Sample session:
b = cint(wscript.stdin.readline) 'force to integer
<pre>
Enter anything other than a number to quit at any time.
 
wscript.stdout.write " First integernumber is: "5
Second number : 23
if a < b then wscript.stdout.write "less than "
5 < 23
if a = b then wscript.stdout.write "equal to "
if a > b then wscript.stdout.write "greater than "
wscript.echo "Second integer."
 
First number : 56
wscript.stdout.write "First integer is " & _
Second number : 6
eef( a < b, "less than ", _
56 > 6
eef( a = b, "equal to ", _
eef( a > b, "greater than ", vbnullstring ) ) ) & "Second integer."
</lang>
 
First number : 4
=={{header|Visual Basic .NET}}==
Second number : 4
'''Platform:''' [[.NET]]
4 == 4
 
First number : q
{{works with|Visual Basic .NET|9.0+}}
</pre>
<lang vbnet>Sub Main()
 
=={{header|XLISP}}==
Dim a = CInt(Console.ReadLine)
<syntaxhighlight lang="xlisp">(DEFUN COMPARE-INTEGERS ()
Dim b = CInt(Console.ReadLine)
(DISPLAY "Enter two integers separated by a space.")
 
(NEWLINE)
'Using if statements
(DISPLAY "> ")
If a < b Then Console.WriteLine("a is less than b")
(DEFINE A (READ))
If a = b Then Console.WriteLine("a equals b")
(DEFINE B (READ))
If a > b Then Console.WriteLine("a is greater than b")
(COND
 
((> A B) (DISPLAY "The first number is larger."))
'Using Case
((= A B) (DISPLAY "They are equal."))
Select Case a
((< A B) (DISPLAY "The first number is smaller."))))</syntaxhighlight>
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|XPL0}}==
<langsyntaxhighlight XPL0lang="xpl0">code IntIn=10, Text=12;
int A, B;
[A:= IntIn(0);
B:= IntIn(0);
if A<B then Text(0, "A<B^M^J");
if A=B then Text(0, "A=B^M^J");
if A>B then Text(0, "A>B^M^J");
CrLf(0);
]</lang>
]</syntaxhighlight>
 
=={{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 2,203 ⟶ 4,558:
<xsl:when test="$a = $b">a = b</xsl:when>
</xsl:choose>
</fo:block></lang>
</xsl:template></syntaxhighlight>
 
=={{header|zkl}}==
<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()</syntaxhighlight>
{{out}}
<pre>
Two ints: 3 2
greater
</pre>
9,482

edits