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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:30:32+00:00 2026-06-12T14:30:32+00:00

I understand all of the following code from an example on a book I’m

  • 0

I understand all of the following code from an example on a book I’m reading. Except the commented line. I’m thinking that without it the loop never ends? I don’t understand the logic behind it though.

var drink = "Energy drink";
var lyrics = "";
var cans = "99";

while (cans > 0) {
    lyrics = lyrics + cans + " cans of " + drink + " on the wall <br>";
    lyrics = lyrics + cans + " cans of " + drink + " on the wall <br>";
    lyrics = lyrics + "Take one down, pass it around, <br>";

    if (cans > 1) {
        lyrics = lyrics + (cans-1) + " cans of" + drink + " on the wall  <br>";
    }
    else {
        lyrics = lyrics + "No more cans of" + drink + " on the wall<br>";
    }
    cans = cans - 1;  // <-- This line I don't understand
}

document.write(lyrics);
  • 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-12T14:30:33+00:00Added an answer on June 12, 2026 at 2:30 pm

    This is a loop that starts at 99 (var cans = "99") then counts backwards to 0. The highlighted line is the line that says “subtract one”. If it weren’t for that line, it would keep looping and adding 99 cans of Energy drink on the wall forever.

    BTW, document.write is just bad, and var cans = "99" should be var cans = 99. Of course, this probably isn’t your code, just sayin’. My advice: keep reading.

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

Sidebar

Related Questions

I'm lead to understand that the following grants all proveleges to all databases that
I am practicing from the book Hello,Android ed3.There is an example code on creating
I am learning re in python. I understand all other things in the following
I'm new to cakephp, but from what I understand all of the database interaction
JavaScript For example, I have the following JavaScript code (Dojo 1.6 is already loaded):
I am trying to understand how Parallelism is implemented in .Net. Following code is
An example from the book Core Python Programming on the topic Delegation doesn't seem
On all my Windows servers, except for one machine, when I execute the following
The following pseudo-code is from the first chapter of an online preview version of
I'm going through the process of learning backbone and don't understand all of the

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.