javascript - Function to exit a parent function -


i have loop runs indefinitely until tell stop. using requestanimationframe , lot more going on, below example simplify question.

var _stop = false;  var loop = function () {     while (!_stop) {         if (some condition met) {             stop();         }          /* something. */          loop();     } };  function stop() {     _stop = true; } 

now works great, still run /* */ 1 more time before stops. want stop , return. of course can done so:

if (some condition met) {     stop();     return; } 

but there way include return part stop();? doesn't want obvious reasons:

function stop() {     _stop = true;     return; } 

but there way achieve this?

var _stop = false; try {   var loop = function () {       if(!_stop) {           if (some condition met) {               stop();           }            /* something. */            loop();       }   }; } catch(e) {  } function stop() {     _stop = true;     throw new error("use precaution"); } 

the loop above job of exiting entire loop, horribly wrong way of doing thing ideally function should

1) mutating state variables

2) or should computing values.

3) or should determining error state stop execution further

it should never bothered how control flow of function caller , ways stop function caller execution flow.


Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -