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
num1 = 100
num2 = 17
num3 = - 90
num4 = - 29
puts num1.succ
puts num2.succ
puts num3.succ
puts num4.succ
|
Output:
101
18
-89
-28
Example 2:
Ruby
num1 = 19
num2 = - 17
num3 = - 18
num4 = 16
puts num1.succ
puts num2.succ
puts num3.succ
puts num4.succ
|
Output:
20
-16
-17
17
Last Updated :
03 Dec, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...