Ruby Integer next function with example
Last Updated :
07 Jan, 2020
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:
num1 = 100
num2 = 17
num3 = - 90
num4 = - 29
puts num1. next
puts num2. next
puts num3. next
puts num4. next
|
Output:
101
18
-89
-28
Example #2:
num1 = 19
num2 = - 17
num3 = - 18
num4 = 16
puts num1. next
puts num2. next
puts num3. next
puts num4. next
|
Output:
20
-16
-17
17
Share your thoughts in the comments
Please Login to comment...