Created
December 13, 2016 22:28
-
-
Save researchranks/80d1f5efa838847b1bee8c1055c72220 to your computer and use it in GitHub Desktop.
javascript generator - while loop conditional
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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