Ruby Integer succ() function with example
The succ 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.succ
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
# Ruby program for succ function # Initializing the numbersnum1 = 100num2 = 17num3 = -90num4 = -29 # Printing the next valueputs num1.succputs num2.succputs num3.succputs num4.succ |
chevron_right
filter_none
Output:
101 18 -89 -28
Example 2:
Ruby
# Ruby program for succ function # Initializing the numbersnum1 = 19num2 = -17num3 = -18num4 = 16 # Printing the succ valueputs num1.succputs num2.succputs num3.succputs num4.succ |
chevron_right
filter_none
Output:
20 -16 -17 17

