Integer comparison: Difference between revisions

→‎{{header|Ruby}}: The first example was broken because the argument to Kernel#gets is the line separator, not the prompt.
(Move 'Korn Shell' to 'UNIX Shell' and backport to pdksh.)
(→‎{{header|Ruby}}: The first example was broken because the argument to Kernel#gets is the line separator, not the prompt.)
Line 1,500:
 
=={{header|Ruby}}==
GetsThis isuses usedKernel#gets to get input from the STDIN, and 'String#to_i' is used to convert the string into an integer. This(Without isthis not explicitly necessaryconversion, since strings will be compared correctly too.Ruby Ifwould twocompare strings: are5 entered< they10 willbut be"5" considered equal using this> method"10".)
 
<lang ruby>a = gets( "enter a value for a: ").to_i
b = gets( "enter a value for b: ").to_i
Line 1,507 ⟶ 1,508:
print "a is greater than b" if a > b
print "a is equal to b" if a == b</lang>
 
Example '''input''' and output:
 
$ '''ruby compare.rb'''
enter a value for a: '''5'''
enter a value for b: '''10'''
5 is less than 10
$ '''ruby compare.rb'''
enter a value for a: '''cat'''
enter a value for b: '''dog'''
0 is equal to 0
 
----
{{trans|Python}}
 
An alternative method, which is similar to the python version mentioned above (at the time of writing this) is:
Anonymous user