Created
July 30, 2014 10:41
-
-
Save ysf/fa2676841263f1206f1b to your computer and use it in GitHub Desktop.
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
| #!/usr/bin/env python | |
| # hack to provide a repeat statement in reply to: https://gist.github.com/ychaouche/f30d5e07012454fff0d2 | |
| import inspect | |
| def repeat(count): | |
| if not hasattr(repeat, "loops"): | |
| repeat.loops = {} | |
| index = "%s#%d" % inspect.getouterframes(inspect.currentframe())[-1][1:3] | |
| if index not in repeat.loops: | |
| repeat.loops[index] = count | |
| if repeat.loops[index] < 0: | |
| repeat.loops[index] = count | |
| repeat.loops[index] -= 1 | |
| return repeat.loops[index] >= 0 | |
| while repeat(2): | |
| while repeat(3): | |
| print "how many times" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment