Flow-control structures: Difference between revisions
Content added Content deleted
(→Case 7 - Creating your own custom exceptions, raise: shorten version) |
(→Case 8 - continue: added "with" statement and "yield" expressions) |
||
Line 462: | Line 462: | ||
main() |
main() |
||
</pre> |
</pre> |
||
===The "with" statement=== |
|||
'''Interpreter:''' [[Python]] 2.6 |
|||
[[Category:Python]] |
|||
See [[http://www.python.org/peps/pep-0343.html PEP 0343, The "with" statement]] |
|||
>>> with open("some_file"): # file ``some_file`` is closed after ``with`` block in any case whether an exception is raised or not |
|||
... raise Exception("an error") |
|||
===Yield expressions=== |
|||
'''Interpreter:''' [[Python]] 2.5 |
|||
[[Category:Python]] |
|||
See [[http://www.python.org/peps/pep-0342.html PEP 0342, Coroutines via Enhanced Generators]] |
|||
>>> value = 1 |
|||
>>> echo = lambda: (yield value) |
|||
>>> for i in echo(): |
|||
... print i |
|||
... |
|||
1 |
|||
=={{header|Tcl}}== |
=={{header|Tcl}}== |