×

Ruby Tutorial

Ruby Basics

Ruby Control Statements

Ruby Methods

Ruby Classes and Methods

Ruby Arrays

Ruby Sets

Ruby Strings

Ruby Classes & Objects

Ruby Hash

Ruby Tools

Ruby Functions

Ruby Built-in Functions

Misc.

Ruby Programs

Ruby program to check a given number is finite or not

Last Updated : December 15, 2025

Problem Solution

In this program, we will create 2 variables and initialize them with some values. Then we will check given number is finite or not using the built-in finite?() function.

Program/Source Code

The source code to check a given number is finite or not is given below. The given program is compiled and executed successfully.

# Ruby program to check a given number 
# is finite or not

num1 = 10;
num2 = 1/0.0;

if num1.finite?()
    print "num1 is a finite number\n";
else
    print "num1 is an infinite number\n";
end

if num2.finite?()
    print "num2 is a finite number\n";
else
    print "num2 is an infinite number\n";
end

Output

num1 is a finite number
num2 is an infinite number

Explanation

In the above program, we created two variables num1, num2 and initialized 10, 1/0.0 respectively. Then we used finite?() function to check given number is a finite number or not and print the appropriate message.

Ruby Basic Programs »


Advertisement
Advertisement


Comments and Discussions!

Load comments ↻


Advertisement
Advertisement
Advertisement

Copyright © 2025 www.includehelp.com. All rights reserved.