Ruby Integer next function with example
The next function in Ruby returns the immediate successor of the number, i.e., it returns number + 1. If a float value is used, it throws an error message.
Syntax: number.next
Parameter: The function takes the integer whose next is to be returned.
Return Value: The function returns the immediate successor of the number, i.e., it returns number + 1
Example #1:
# Ruby program of next function # Initializing the numbers num1 = 100num2 = 17num3 = -90num4 = -29 # Printing the modulo valueputs num1.nextputs num2.nextputs num3.next puts num4.next |
Output:
101 18 -89 -28
Example #2:
# Ruby program of next function # Initializing the numbers num1 = 19num2 = -17num3 = -18num4 = 16 # Printing the modulo valueputs num1.nextputs num2.nextputs num3.next puts num4.next |
Output:
20 -16 -17 17


