Python Forum

Full Version: for/else ... for/elif?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
an else: can follow a loop to handle the case of no break statements being done in that loop. but if the first thing that needs to be done in that else: block is an if statement, can that be coded as an elif statement instead of an else: followed by an (indented) if?
The answer (no) is in this part of the documentation of python's syntax.
thanks. i do remember seeing some language long ago which implemented elif by rebuilding the code. i don't think it had else for loops but if it did, coding elif would have created the else block and the if block, so it would have worked there. i just didn't know if Python could have been doing the same kind of thing.