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 7992679
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T13:38:10+00:00 2026-06-04T13:38:10+00:00

I wonder why the first approach to factorial does not work (infinite loop) in

  • 0

I wonder why the first approach to factorial does not work (infinite loop) in ruby while the second does.

def fac (x)
  if x == 0
    return 1
  else
    return (fac (x-1) * x)
  end
end

def fact( num )
  return 1 if num == 0

  fact(num - 1) * num
end
  • 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-06-04T13:38:12+00:00Added an answer on June 4, 2026 at 1:38 pm

    The difference is the space after the method name, not the way you structured your if-else.

    fac (x-1) * x is parsed as fac((x-1) * x). Basically if a method name is followed by a space (or any token that is not an opening parenthesis), ruby assumes you’re calling the method without parentheses. So it interprets the parentheses around x-1 as grouping, not a part of the method call syntax.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wonder why these statements are not the same (the first one worked for
I just wonder what the best approach is to have multiple users work on
This is my first question on stackoverflow. I just wonder why my getJSON code
I wonder when we write a program in PHP, Ruby, or Python, how do
here is some C# code that does not compile, giving the following message :
I wonder where and what I have to edit to make the first column
I wonder if it is possible to get information about all first level dependencies
My first question : I wonder how you compile your vhdl file under ghdl
EF4.1-Code-First-Gurus! I wonder if there is a more elegant way to handle the following
I am using cobertura first time. Everything works fine but what I wonder is,

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.