Anonymous user
Flow-control structures: Difference between revisions
m
Speling/grammar/aesthetics
m (→Exceptions: Added note on usage) |
m (Speling/grammar/aesthetics) |
||
Line 1:
{{Task}}
{{Control Structures}}
In this task, we document common flow-control structures.
▲In this task, we document common flow-control structures. One common example of a flow-control structure is the <code>goto</code> construct. Note that [[Conditional Structures]] and [[Loop Structures]] have their own articles.
=={{header|Ada}}==
Line 204 ⟶ 202:
===goto===
Goto is typically looked down upon by most
FORK:
Line 228 ⟶ 226:
===goto===
goto l transfers control to the label l.
nested loops:
Line 263 ⟶ 261:
</pre>
Pop11 goto is a nonlocal one, so "jump out" from a chain of procedure calls:
<pre>
Line 279 ⟶ 276:
</pre>
This is useful to exit early from
===go_on===
Line 290 ⟶ 286:
</pre>
If expression has value K the above will jump to label labK, if expression is not an integer, or if it outside range from 1 to N, then control passes to label elselab. The else part may be omitted (then out of range values of expression cause an exception).
There is a more structured variant of go_on:
Line 303 ⟶ 296:
endgo_on;
where lab is a prefix
===return===
return ends execution of current function.
it is just:
Line 322 ⟶ 315:
===chain===
chain has effect of "tail call" but is not
<pre>
Line 329 ⟶ 321:
</pre>
finishes execution of proc1 and transfers control to the proc2 passing it x1, x2, and x3 as arguments. On return from proc2 control passes to caller of proc1.
Remark: Pop11 does not perform "tail call optimization", one has to explicitly use chain.
=={{header|Python}}==
Line 466 ⟶ 455:
===The "with" statement===
'''Interpreter:''' [[Python]] 2.6
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
Line 472 ⟶ 460:
===Yield expressions===
'''Interpreter:''' [[Python]] 2.5
See [[http://www.python.org/peps/pep-0342.html PEP 0342, Coroutines via Enhanced Generators]]
>>> value = 1
|