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

  • Home
  • SEARCH
  • 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 8953445
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:05:46+00:00 2026-06-15T14:05:46+00:00

I need to pause a for loop and not continue until I specify. For

  • 0

I need to pause a for loop and not continue until I specify. For each item in the array that I’m looping through, I run some code that runs an operation on a separate device, and I need to wait until that operation is finished before looping to the next item in the array.

Fortunately, that code/operation is a cursor and features an after: section.

However, it’s been running the entire for loop instantly, which I need to prevent. Is there any way to prevent the loop from continuing until specified? Or perhaps a different type of loop or something that I should use?

My first (poor) idea was to make a while-loop within the for-loop that ran continuously, until the after: portion of the cursor set a boolean to true. This just locked up the browser 🙁 As I feared it would.

Anything I can do? I’m fairly new to javascript. I’ve been enjoying my current project though.

Here’s the while-loop attempt. I know it’s running the entire loop immediately because the dataCounter goes from 1 to 3 (two items in the array currently) instantly:

if(years.length>0){
  var dataCounter = 1;
  var continueLoop;
  for(var i=0;i<years.length;i++){
    continueLoop = false;
    baja.Ord.make(historyName+"?period=timeRange;start="+years[i][1].encodeToString()+";end="+years[i][2].encodeToString()+"|bql:select timestamp, sum|bql:historyFunc:HistoryRollup.rollup(history:RollupInterval 'hourly')").get(
        {
          ok: function (result) {
          // Iterate through all of the Columns

          baja.iterate(result.getColumns(), function (c) {
            baja.outln("Column display name: " + c.getDisplayName());
          });
        },
        cursor: {
          before: function () {
          baja.outln("Called just before iterating through the Cursor");
          counter=0;
          data[dataCounter] = [];
          baja.outln("just made data["+dataCounter+"]");
        },
        after: function () {
          baja.outln("Called just after iterating through the Cursor");
          continueLoop = true;
        },
        each: function () {

          if(counter>=data[0].length) {
            var dateA = data[dataCounter][counter-1][0];
            dateA += 3600000;
          }
          else {
            var dateA = data[0][counter][0];
          }

          var value=this.get("sum").encodeToString();
          var valueNumber=Number(value);

          data[dataCounter][counter] = [dateA,valueNumber];
          counter++;
        },
        limit: 744, // Specify optional limit on the number of records (defaults to 10)2147483647
        offset: 0 // Specify optional record offset (defaults to 0)
        }
        })
        while(continueLoop = false){
          var test = 1;
          baja.outln("halp");
        }
    dataCounter++;
  }
}
  • 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-15T14:05:47+00:00Added an answer on June 15, 2026 at 2:05 pm

    Do not use a for loop to loop on each element. You need, in the after: to remember which element of the array you’ve just done and then move to the next one.

    Something like this :

    var myArray = [1, 2, 3, 4]
    
    function handleElem(index) {
        module.sendCommand({
            ..., // whatever the options are for your module
            after: function() {
                if(index+1 == myArray.length) {
                    return false; // no more elem in the array
                } else {
                    handleElem(index+1)}  // the after section
                }
        });
    }
    
    handleElem(0);
    

    I assumed that you call a function with some options (like you would for $.ajax()) and that the after() section is a function called at the end of your process (like success() for $.ajax())

    If the “module” you call is not properly ended in the after() callback you could use setTimeout() to launch the process on the next element with a delay

    EDIT: With your real code it would be something like this :

    function handleElem(index) {
        baja.Ord.make("...start="+years[index][1].encodeToString()+ "...").get(
        {
            ok: ...
            after: function() {
                if(index+1 == years.length) {
                    return false; // no more elem in the array
                } else {
                    handleElem(index+1)}  // the after section
                }
            }
        });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need parse through a file and do some processing into it. The file
I need to parse through a string and add single quotes around each Guid
Using Javascript, I'm trying to loop through an array and execute a function with
I working with some EBCDIC data that I need to parse and find some
I have a jquery cycle slider that I need to pause either when a
This is some basic code for an array I'm writing. I need to fill
I need to do a sort of timeout or pause in my method for
Need to parse a file for lines of data that start with this pattern
i need to parse simple JSON php in my tableview for that i searched
I have two videos, and I want to loop the first video until 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.