4 ms·
def stub(): while(False): print("smart stuff") print("hello, world") stub() If you remove the `while(False)` loop, the working cod
by SiVal 11y ago
def stub():
while(False):
print("smart stuff")
print("hello, world")
stub()
If you remove the `while(False)` loop, the working code will stop working.
- loup-vaillant 11y agoOh, come on, that's an obvious one. Obviously, "removing the while(False) loop" in this case means replacing it with an empty return: def stub(): return print("hello, world") stub() There, it works. That said, boo Python for not admitting empty bodies. It needlessly adds a special case to its syntax. I suspect this comes from the implementation of its lexer.
- ggambetta 11y ago"pass"?
- johnmaguire2013 11y agoThe keyword pass is used in place of an empty body. Explicit better than implicit, etc.
- SiVal 11y agoThe question I answered was: "How is this even possible?" (emphasis in the original). The implication seems to be that it should not be possible for the removal of a `while(False)` statement to break working code, presumably based on the assumption that it can't do anything. Yet that is a false assumption, and lots of bugs are based on assumptions that seem true yet, strictly speaking, don't have to be. I provided an existence proof that it IS possible and one minimal example that the assumption that such code literally can't play any role in whether code works or not is incorrect.
- loup-vaillant 11y agoThe post I was replying to said `while(false){}`. It did not say `while(False)`. It was implied that we were talking about a C based language. You proved nothing. Others did.