I'm coming from Tcl-world ...
Daniel Fackrell
unlearned at DELETETHIS.learn2think.org
Tue Aug 6 13:15:29 EDT 2002
"Andreas Leitgeb" <Andreas.Leitgeb at siemens.at> wrote in message
news:slrnal016g.c05.Andreas.Leitgeb at pc7499.gud.siemens.at...
> Christos TZOTZIOY Georgiou <DLNXPEGFQVEB at spammotel.com> wrote:
> > [example snipped, because it turned out too trivial to convey the point]
>
> new example:
> for (<init>; <cond-a>; <incr>) {
> if (<cond-b>) {
> try { // is C++, but doesn't matter
> <code-a>
> if (<cond-c>) continue;
> <code-b>
> } catch(...) {
> <code-c>
> }
> <code-d>
> } else {
> <code-e>
> }
> }
> Python: ?
> With some effort, one can surely craft equivalent code in Python,
> but I bet it will become considerably longer, and likely you'll
> have to repeat some of the code-blocks, or introduce new flag-variables.
> point taken ?
<init>
while <cond-a>:
<incr>
if <cond-b>:
try:
<code-a>
if <cond-c>:
continue
<code-b>
except (...):
<code-c>
<code-d>
else:
<code-e>
It appears to translate in a rather straightforward manner to me.
If you are concerned about the lack of the i++ equivalent, then start the
loop one lower. If you are also dependent on the side effect of i being one
greater at the end of the loop, increment it after the loop, but it seems
that such a case as that would be rather rare.
But in any case, I think the only code that might be repeated would be along
the lines of:
i += 1
, and then only if you are dependent on i being incremented at the end of
the loop.
Does that help at all?
--
Daniel Fackrell (unlearned at learn2think.org)
When we attempt the impossible, we can experience true growth.
More information about the Python-list
mailing list