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.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 for succ function # Initializing the numbers num1 = 100 num2 = 17 num3 = -90 num4 = -29 # Printing the next value puts num1.succ puts num2.succ puts num3.succ puts num4.succ |
Output:
101 18 -89 -28
Example 2:
# Ruby program for succ function # Initializing the numbers num1 = 19 num2 = -17 num3 = -18 num4 = 16 # Printing the succ value puts num1.succ puts num2.succ puts num3.succ puts num4.succ |
Output:
20 -16 -17 17
Recommended Posts:
- Ruby | Time succ() function
- Ruby | Symbol succ function
- Ruby Integer integer? function with example
- Ruby Integer odd? function with example
- Ruby Integer div() function with example
- Ruby Integer chr function with example
- Ruby Integer even? function with example
- Ruby Integer next function with example
- Ruby Integer gcd() function with example
- Ruby Integer abs() function with example
- Ruby | Integer >= function
- Ruby | Integer - function
- Ruby | Integer <=> function
- Ruby Integer lcm() function with example
- Ruby | Integer << function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


