Quantcast
Channel: Hot Weekly Questions - Web Applications Stack Exchange
Viewing all articles
Browse latest Browse all 9782

Google Apps Script While Loop does not stop when it should

$
0
0

I'm new to Google Apps Script. I am trying to write a while loop for a spreadsheet, but the loop isn't stopping when it should.

The spreadsheet contains a formula that returns randomized Sudoku puzzles but the randomized results will sometimes include #N/A errors.

I have another formula in L3 that returns the string "ERROR" if the randomized result contains an error otherwise it returns "WORKS".

My while loop in GAS is intended to trigger the random puzzle generator to re-run when it detects the string "ERROR" in L3 by adding 1 to the value in N2.

My Script
function IterationMacro() {  var spreadsheet = SpreadsheetApp.getActive();  var errorValue = spreadsheet.getRange('L3').getValue();    while(errorValue == 'ERROR'){      var modRange = spreadsheet.getRange('N2');      var modValue = modRange.getValue();      modRange.setValue(modValue + 1);      var errorValue = spreadsheet.getRange('L3').getValue();    };};

In theory, the script should continue to add 1 to the value in N2 until an error-free puzzle is generated, which would cause the value in L3 to be "WORKS" instead of "ERROR"

Unfortunately, it doesn't seem to stop. I have run the macro and watched it add 1 until cell L3="WORKS" but the value change is ignored and the script continues adding 1 to the value in N2 indefinitely.

Why doesn't the script stop when the value changes?


Viewing all articles
Browse latest Browse all 9782

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>