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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:36:22+00:00 2026-05-31T21:36:22+00:00

I was playing around with the following code: function recaller(){ while(x– > 0)recaller(); }

  • 0

I was playing around with the following code:

function recaller(){
    while(x-- > 0)recaller();
}

var x = 10;
recaller();
alert(x); //-11?

But I was astonished to find that the x now holds the value of -11

I later added alert(x); above the while, to see if it displayed correctly the numbers 10 to 0 and it did.

Can someone explain me where did the -11 came from?, my debugging skills failed me this time and I have no clue how to keep testing

  • 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-31T21:36:23+00:00Added an answer on May 31, 2026 at 9:36 pm

    You are recursing into recaller, so x gets decremented lots of times at the end of the recursion — for each time you recurse, when you exit that recursive call the while loop condition will be checked again, and that expression decrements x. Consider what happens if we start with x = 2:

    1. x is 2, we call recaller (first time) enter its while loop which checks x is greater than zero, decrements and…
    2. x is 1, we call recaller (second time) enter its while loop which checks x is greater than zero, decrements and…
    3. x is 0, we call recaller (third time) enter its while loop which checks x is greater than zero which it isn’t, decrements (-1) and returns
    4. unwind the stack once to the second time; in its while loop, check x is greater than zero (no), decrements (-2) and returns
    5. unwind the stack once to the first time; in its while loop, check x is greater than zero (no), decrements (-3) and returns
    6. return to top level flow
    7. x=-3
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I came across on a strange behavior of the following code, while playing around
I was playing around with this code. http://programmersvoice.com/tag/code And I noticed that the following
i'm playing around with building a sql function that will extract numbers from a
I'm playing around with the following code. The intention is to open a new
I was playing around with some code today, and was very surprised to find
might be a silly question nonetheless: I'm playing around with the following code: $a='a';
I'm playing around with wpf and I saw the following article: WPF ListView Inactive
I've been playing around with Spring Security a bit and noticed the following oddity.
Playing around with MongoDB and NoRM in .NET. Thing that confused me - there
Just playing around with the now released Silverlight 2.0. I'm trying to put a

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.