Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6598285
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:19:34+00:00 2026-05-25T18:19:34+00:00

def getPrime(testNumber) temp1=testNumber -1; bIsPrime = false; while (temp1 > 1) do bIsPrime =

  • 0
def getPrime(testNumber)
    temp1=testNumber -1;
    bIsPrime = false;
    while (temp1 > 1) do
        bIsPrime = ((testNumber % temp1) == 0)  
        puts("Check 1 #{((testNumber % temp1) == 0)}, temp1=#{temp1} ");
        if ($bIsPrime) 
            break;
        else
            temp1 = temp1-1;
        end
    end
    return bIsPrime
end

puts("Enter any number to know if it's Prime or not");

testNumber = gets()

returnVal = getPrime(Integer(testNumber));

puts("Is enternered number Pime? #{return}");

I have just started with Ruby…So to begin with i tried to write a prime number program.

This thing is giving error “unexpected return”

Any help would be great. Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T18:19:35+00:00Added an answer on May 25, 2026 at 6:19 pm

    although you already have your answer I thought it would be helpful to drop this here, it follows the same idea you’re using in your code:

    def is_prime?(test_number)
        (2..test_number-1).reverse_each do |i|
            divisible = (test_number % i == 0)
            puts "Check ##{test_number-i}, divisible=#{divisible}, temp=#{i}"
            return false if divisible
        end
        return true
    end
    puts "Enter any number to know if it's prime or not"
    test_number = gets.chomp.to_i
    puts "Is entered number prime? #{is_prime?(test_number)}"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

def any? if block_given? method_missing(:any?) { |*block_args| yield(*block_args) } else !empty? end end In
def update @album = Album.find(params[:id]) if @album.update_attributes(params[:album]) redirect_to(:action=>'list') else render(:action=>'edit') end end A Rails
def isBig(x): if x > 4: return 'apple' else: return 'orange' This works: if
def remove_section(alist, start, end): Return a copy of alist removing the section from start
def binarysearch(a, b, tofind, stringarray) k=(a+b)/2 if a==b return nil end if (stringarray[k]).include? tofind
def subStringMatchExact(target, key): if (target.find(key) == -1): return [] else: foundStringAt = [target.find(key)] target
def next_prime_number (last_known_prime) while true last_known_prime++ found_factor = false # ERROR for i in
def Input(): c = raw_input ('Enter data1,data2: ') data = c.split(',') return data I
def partial(template, *args) options = args.extract_options! options.merge!(:layout => false) if collection = options.delete(:collection) then
def test_method [a, b, c].map {|i| yield(i) } end If I call test_method like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.