samedi 4 avril 2015

Is using a while loop + break an acceptable way to "goto" the end of an operation?

I had a hard time constructing a query to find an answer to this-- I am interested if anybody has any input or an alternative to this scenario:


I am performing a bunch of operations in succession on a variable. If one of these operations makes the variable meet a certain condition, I want to go ahead and skip the rest of the operations.


How I have been doing this:



while(true) {
variable x;
performOperation1();
if( x meets conditions ) break;
performOperation2();
if( x meets conditions ) break;
performOperation3();
if( x meets conditions ) break;
//...etc
}


I think this problem is language agnostic, but I tagged it JavaScript because that's where I'm facing the problem right now.


Aucun commentaire:

Enregistrer un commentaire