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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:36:38+00:00 2026-06-01T12:36:38+00:00

The method constructBuilder() shouldn’t go infinitely because it is set to loop only 10

  • 0

The method constructBuilder() shouldn’t go infinitely because it is set to loop only 10 times and the value of data.length never changes.

This loop & method infact works perfectly, until I call another method within the loop.

When I call the method getOptions(type) inside this loop, the value of i changes very strangely, and always follows this pattern:

1st run: i=0
2nd run: i=1
3rd run: i=3
4th run: i=5
5th run: i=6
6th run: i=4
7th run: i=4
8th run: i=4
nth run: i=4

the value of i gets stuck at 4, doesn’t increment and the loop runs infinitely!

Why does this happen??

Here is the code:

var data = [["Text Array", "Some more text", "btnText", "btn2text"],
            ["Text2", "2: more text", "btnText2", "btn2text2"],
            ...
           ];

var products, order;

function initialise() {
    products = loadProducts();
    order = new Order();
    constructBuilder();
}

function constructBuilder() {
    var qb_boxes_innerHTML = "";
    for (i=0; i<data.length; i++) {
      alert("i="+i + "; data length="+data.length);
      var box_innerHTML = "<table width=100% height=100% cellpadding=0; cellspacing=0; border=0>";
      box_innerHTML += "<tr><td width=100% height=\"50px\">" + data[i][0] + "</td></tr>";
      box_innerHTML += "<tr><td width=100% class=\"scroll\" valign=\"top\">" + data[i][1] + getOptions(i) + "</td></tr>";
      box_innerHTML += "<tr><td width=100% height=\"50px\" align=\"right\" valign=\"middle\"><form action=\"javascript:next();\"><input type=\"button\" value=\""
                    + data[i][2] + "\" onClick=\"prev();\"/><input id=\"continueBtn\" type=\"submit\" value=\""
                    + data[i][3] + "\" disabled/></form></td></tr>";
      box_innerHTML += "</table>";
      qb_boxes_innerHTML += "<div id=\"qb_box" + i + "\" class=\"qb_box\" style=\"visibility: hidden;\">" + box_innerHTML + "</div>";
    }
    document.getElementById("qb_boxes").innerHTML = qb_boxes_innerHTML;
    document.getElementById("qb_box0").style.visibility = "";
}
function getOptions(type) {
    var optionsList = getProducts(products, type);
    var options_html = "";
    for (i=0; i<optionsList.length; i++) {
      options_html += "<input id=\"check"+type+"_"+i+"\" type=\"checkbox\"/>" + optionsList[i].name + "<BR/>";
    }
    return options_html;
}

function getProducts(productList, type) {
      var productsOfType = new Array();
      for (i=0; i<productList.length; i++) {
        if (productList[i].type == type)
            productsOfType.push(productList[i]);
      }
      return productsOfType;
}

If you need any more info, please comment.

Thanks for looking.

  • 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-01T12:36:39+00:00Added an answer on June 1, 2026 at 12:36 pm

    By using i without var you’re actually using a global variable window.i. Alter your functions so that i gets declared as local variable:

    function constructBuilder() {
        var qb_boxes_innerHTML = "";
        var i;
        /* ... */
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Method chaining is the only way I know to build fluent interfaces. Here's an
What method do you use when you want to get performance data about specific
Following method is accepted if I set UIColor like: [tabBarController.tabBar setSelectedImageTintColor:[UIColor greenColor]]; However I
This method works great and generates only 1 query (utilizing .Includes() to eager load).
My method saveNote uses selectedNote in its core data context save operation. Is it
This method notifes an event loop to start processing a message. However, if the
My method has a parameter, I have to use that in my For loop
Which method of the lifecycle is called when orientation changes occur? My application executes
If method A() calls static method B() , this is bad because the two
Every method accepts a set of parameter values. Should we always validate the non-nullness

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.