Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save researchranks/80d1f5efa838847b1bee8c1055c72220 to your computer and use it in GitHub Desktop.
Save researchranks/80d1f5efa838847b1bee8c1055c72220 to your computer and use it in GitHub Desktop.
javascript generator - while loop conditional
function * counter(){
var c = 0;
var state = yield null;
while(true){
if(state === false){
return;
}
yield c++;
}
}
var count = counter();
for(var amount of count){
if( count.next().value > 100 ){
count.next(false);
return;
}else{
log( count.next() );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment