0

I have an excel spreadsheet with a circular reference. By default, Excel will not calculate the cell. However, you can override this default behavior and force it to calculate a cell with a circular reference. You just need to set the number of iterations before it should stop (or use its default 100 iterations).

If I want to reproduce Excel's handling of this situation with JavaScript, can I simply wrap my function in a for loop, iterate a counter, and end the function calls when the counter hits a specified number? Or am I missing something more intricate in what Excel is doing with its iteration limit?

I apologize for the abstract nature of the request. I don't have an exact example at the moment, but could produce one if necessary.

technoTarek
  • 3,218
  • 2
  • 21
  • 25

1 Answers1

1

You could do something like this:

var counter = 0;

function foo(){
    //do something
    counter++;
    if(counter < 100)
        bar();
}

function bar(){
    //do something
    foo();
}

That's a circular call that will end when counter reaches 100.

mornaner
  • 2,424
  • 2
  • 27
  • 39
  • Thanks, your example demonstrates a circular reference in JS. Can you comment on whether this achieves the exact same effect as Excel's circular iteration capability? – technoTarek Sep 05 '12 at 13:28