Skip to content
Related Articles

Related Articles

Improve Article

Ruby Integer next function with example

  • Last Updated : 07 Jan, 2020
Geek Week

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 = 100
num2 = 17
num3 = -90
num4 = -29
      
# Printing the modulo value
puts num1.next
puts num2.next
puts num3.next 
puts num4.next 

Output:

101
18
-89
-28

Example #2:




# Ruby program of next function
  
# Initializing the numbers 
num1 = 19
num2 = -17
num3 = -18
num4 = 16
     
# Printing the modulo value
puts num1.next
puts num2.next
puts num3.next 
puts num4.next 

Output:

20
-16
-17
17
My Personal Notes arrow_drop_up
Recommended Articles
Page :